-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from Giveth/develop
Staging to main
- Loading branch information
Showing
21 changed files
with
253 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = class Data1724279465327 { | ||
name = "Data1724279465327"; | ||
|
||
async up(db) { | ||
await db.query(`ALTER TABLE "project" DROP COLUMN "source_status"`); | ||
await db.query(`ALTER TABLE "project" ADD "rf_rounds" integer array`); | ||
} | ||
|
||
async down(db) { | ||
await db.query(`ALTER TABLE "project" DROP COLUMN "rf_rounds"`); | ||
await db.query(`ALTER TABLE "project" ADD "source_status" text`); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SourceConfig } from "../types"; | ||
import { RoundNumber } from "./type"; | ||
|
||
// Define RL_API_URLS with specific round number keys | ||
export const RL_API_URLS: Record<RoundNumber, string> = { | ||
4: process.env.RL4_API_URL || "https://round4-api-eas.retrolist.app/projects", | ||
5: | ||
process.env.RL5_API_URL || | ||
"https://round5-api-eas.retrolist.app/5/projects", | ||
}; | ||
|
||
export const rlSourceConfig: SourceConfig = { | ||
source: "rf", | ||
idField: "id", | ||
titleField: "name", | ||
descriptionField: "description", | ||
imageField: "bannerImageUrl", | ||
urlField: "url", | ||
rfRoundField: "rfRound", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type RlProjectInfo } from "./type"; | ||
|
||
export const generateRlUrl = (project: RlProjectInfo) => { | ||
return `/project/${project.id}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { updateOrCreateProject } from "../helpers"; | ||
import { rlSourceConfig } from "./constants"; | ||
import { generateRlUrl } from "./helper"; | ||
import { fetchRlProjects } from "./service"; | ||
|
||
export const fetchAndProcessRlProjects = async (round: number) => { | ||
try { | ||
const data = await fetchRlProjects(round); | ||
if (!data) return; | ||
for (const project of data) { | ||
const processedProject = { | ||
...project, | ||
url: generateRlUrl(project), | ||
rfRound: round, | ||
}; | ||
|
||
await updateOrCreateProject(processedProject, rlSourceConfig); | ||
} | ||
} catch (error: any) { | ||
console.log("error on fetchAndProcessRlProjects", error.message); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Assuming RL_API_URLS and RlProjectInfo are defined as mentioned | ||
import { RL_API_URLS } from "./constants"; | ||
import { RlProjectInfo, RoundNumber } from "./type"; | ||
|
||
export const fetchRlProjects = async ( | ||
round: number | ||
): Promise<RlProjectInfo[] | null> => { | ||
console.log(`Fetching RL projects for round ${round}`); | ||
try { | ||
// Check if the round exists in RL_API_URLS | ||
if (!(round in RL_API_URLS)) { | ||
console.log(`Invalid round number: ${round}`); | ||
return null; | ||
} | ||
|
||
// Use type assertion to narrow down the type of 'round' to RoundNumber | ||
const url = RL_API_URLS[round as RoundNumber]; | ||
const res = await fetch(url, { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
// Check if the response is ok (status code in the range 200-299) | ||
if (!res.ok) { | ||
console.log(`Failed to fetch data: ${res.status} ${res.statusText}`); | ||
return null; | ||
} | ||
|
||
const data: RlProjectInfo[] = await res.json(); | ||
console.log(`Fetched ${data.length} projects for round ${round}`); | ||
|
||
return data; | ||
} catch (error: any) { | ||
console.log("Error on fetching fetchRlProjects", error.message); | ||
return null; | ||
} | ||
}; |
4 changes: 3 additions & 1 deletion
4
src/features/import-projects/rf4/type.ts → ...eatures/import-projects/retroList/type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { SourceConfig } from "../types"; | ||
|
||
export const RF_API_URL = | ||
process.env.RF4_API_URL || "https://vote.optimism.io/api/v1"; | ||
|
||
export const rfSourceConfig: SourceConfig = { | ||
source: "rf", | ||
idField: "id", | ||
titleField: "name", | ||
descriptionField: "description", | ||
imageField: "projectCoverImageUrl", | ||
urlField: "url", | ||
rfRoundField: "rfRound", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { updateOrCreateProject } from "../helpers"; | ||
import { rfSourceConfig } from "./constants"; | ||
import { RfProjectInfo } from "./type"; | ||
|
||
export const generateRfUrl = (project: RfProjectInfo) => { | ||
return `/project/${project.id}`; | ||
}; | ||
|
||
const processProject = (project: RfProjectInfo, round: number) => { | ||
const projectData = { | ||
...project, | ||
url: generateRfUrl(project), | ||
rfRound: round, | ||
}; | ||
return projectData; | ||
}; | ||
|
||
export const saveBatchProjects = async ( | ||
projects: RfProjectInfo[], | ||
round: number | ||
) => { | ||
for (const _project of projects) { | ||
const project = processProject(_project, round); | ||
await updateOrCreateProject(project, rfSourceConfig); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { AGORA_API_KEY } from "../../../constants"; | ||
import { RF_API_URL } from "./constants"; | ||
import { saveBatchProjects } from "./helpers"; | ||
import { RfApiResponse, RfProjectInfo } from "./type"; | ||
|
||
export const fetchRFProjectsByRound = async (round: number) => { | ||
let offset = 0; | ||
const limit = 10; | ||
let hasNext = true; | ||
|
||
console.log( | ||
`[${new Date().toISOString()}] - Fetching projects for round: ${round}` | ||
); | ||
|
||
if (!AGORA_API_KEY) { | ||
console.error("AGORA_API_KEY is not set"); | ||
return; | ||
} | ||
|
||
try { | ||
while (hasNext) { | ||
const response = await fetch( | ||
`${RF_API_URL}/retrofunding/rounds/${round}/projects?limit=${limit}&offset=${offset}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${AGORA_API_KEY}`, | ||
}, | ||
} | ||
); | ||
console.log( | ||
`[${new Date().toISOString()}] - Fetching projects for round: ${round} at offset: ${offset} - ${response.status} - ${response.ok}` | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`HTTP error! status: ${response.status} for round: ${round} at offset: ${offset}` | ||
); | ||
} | ||
|
||
const res: RfApiResponse = await response.json(); | ||
|
||
await saveBatchProjects(res.data, round); | ||
|
||
hasNext = res.meta.has_next; | ||
offset = res.meta.next_offset; | ||
} | ||
} catch (error) { | ||
console.error( | ||
`Error fetching projects for round: ${round} at offset: ${offset}`, | ||
error | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export interface RfProjectInfo { | ||
id: string; | ||
category: string; | ||
organization: string | null; | ||
name: string; | ||
description: string; | ||
profileAvatarUrl: string; | ||
projectCoverImageUrl: string; | ||
team: string[]; | ||
github: string[]; | ||
packages: string[]; | ||
links: string[]; | ||
} | ||
|
||
export interface RfApiResponse { | ||
meta: { | ||
has_next: boolean; | ||
total_returned: number; | ||
next_offset: number; | ||
}; | ||
data: RfProjectInfo[]; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.