Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Remove Handles from Graph #6040

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1e0b2bf
wip snip
joshuashort Dec 13, 2022
9267a8e
added netlify function for call handles, updated judge application by…
hannahtuttle Dec 14, 2022
aa6087d
cleanup judge page
joshuashort Dec 15, 2022
8578337
Disable query in manage-team
joshuashort Dec 15, 2022
70eddfc
Disable query in register-team
joshuashort Dec 15, 2022
144f876
wip get-user endpoint full list
joshuashort Dec 15, 2022
29a395d
Merge branch 'dzhawsh/user-endpoint-test' into 6039-feature-remove-ha…
joshuashort Dec 15, 2022
bef3800
testing new handles
hannahtuttle Dec 15, 2022
29d2f2e
Merge branch '6039-feature-remove-handles-from-graph' of https://gith…
hannahtuttle Dec 18, 2022
4b3c53f
Merge branch '6039-feature-remove-handles-from-graph' of https://gith…
hannahtuttle Dec 18, 2022
78757b5
updated register.tsx to use netlify handles
hannahtuttle Dec 18, 2022
25f945e
updated register team to use handles endpoint
hannahtuttle Dec 18, 2022
fddfc0f
updated manage teams, started testing the get-user function, updated …
hannahtuttle Dec 18, 2022
ce048f6
added file back in that was deleted durig the last merge
hannahtuttle Dec 19, 2022
59b669c
added formatting to json handle
hannahtuttle Dec 19, 2022
aaaaf28
removed extra space
hannahtuttle Dec 19, 2022
67f2757
[UPD] identation
Simon-Busch Jan 24, 2023
24e9d02
Merge branch 'main' into 6039-feature-remove-handles-from-graph
Simon-Busch Jan 24, 2023
afb4a6d
[UPD] refactor getHandles
Simon-Busch Jan 24, 2023
a2543c6
Merge branch 'main' into 6039-feature-remove-handles-from-graph
Simon-Busch Jan 24, 2023
94bd2e5
Merge branch 'main' into 6039-feature-remove-handles-from-graph
Simon-Busch Jan 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ const plugins = [
name: `orgs`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/_data/handles`,
name: `handles`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
Expand Down
11 changes: 8 additions & 3 deletions netlify/functions/get-user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findUser } from "../util/user-utils";
import { findUser, getUsers } from "../util/user-utils";

exports.handler = async (event) => {
// only allow GET
Expand All @@ -12,11 +12,16 @@ exports.handler = async (event) => {

const userHandle = event.queryStringParameters.id;
try {
const user = await findUser(userHandle);
let res;
if (userHandle === undefined) {
res = getUsers();
} else {
res = await findUser(userHandle);
}

return {
statusCode: 200,
body: JSON.stringify(user),
body: JSON.stringify(res),
};
} catch (error) {
return {
Expand Down
59 changes: 59 additions & 0 deletions netlify/functions/handles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import fs, { readFileSync, readdirSync } from "fs";

const readAndParseJSONFile = (filePath: string) => {
const buffer = readFileSync(filePath);
return JSON.parse(buffer.toString());
};

const getImageUrl = (fileData: any) => {
if (fileData.image) {
const imagePath = fileData.image.slice(2);
return `https://raw.githubusercontent.com/${process.env.GITHUB_REPO_OWNER}/${process.env.REPO}/${process.env.BRANCH_NAME}/_data/handles/${imagePath}`;
}
return null;
};

const getHandles = () => {
const allHandles: {
handle: string;
link: string;
moralisId: string;
imageUrl: string;
members: string[];
}[] = [];

const files = readdirSync(`./_data/handles`);
for (const file of files) {
if (file.endsWith(".json")) {
const fileData = readAndParseJSONFile(`./_data/handles/${file}`);
const imageUrl = getImageUrl(fileData);
allHandles.push({ ...fileData, imageUrl });
}
}
return allHandles;
};

exports.handler = async (event) => {
// only allow GET
if (event.httpMethod !== "GET") {
return {
statusCode: 405,
body: "Method not allowed",
headers: { Allow: "GET" },
};
}

try {
// handle
const allHandles = getHandles();
return {
statusCode: 200,
body: JSON.stringify(allHandles),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({ error: error.toString(), details: error.stack }),
};
}
};
57 changes: 56 additions & 1 deletion netlify/util/user-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from "fs";
import { readFileSync, readdirSync } from "fs";
import Moralis from "moralis-v1/node";
import fetch from "node-fetch";
import uniq from "lodash/uniq";
Expand Down Expand Up @@ -43,6 +43,61 @@ export async function findUser(userHandle) {
}
}

export async function getUsers() {
const allHandles: {
handle: string;
link: string;
moralisId: string;
image: string;
}[] = [];
const data = readdirSync(`./_data/handles`);
// just return the objects?
// without members
data.forEach((file) => {
if (file.endsWith(".json")) {
const buffer = readFileSync(`./_data/handles/${file}`);
const wardenFileData = JSON.parse(buffer.toString());
if (wardenFileData.image) {
const imagePath = wardenFileData.image.slice(2);
wardenFileData.imageUrl = `https://raw.githubusercontent.com/${process.env.GITHUB_REPO_OWNER}/${process.env.REPO}/${process.env.BRANCH_NAME}/_data/handles/${imagePath}`;
}
if (!wardenFileData.members) {
allHandles.push({ ...wardenFileData });
}
}
});
return allHandles;
}

export async function getTeams() {
// just return the objects?
// with members
const teamHandles: {
handle: string;
link: string;
moralisId: string;
image: string;
}[] = [];
const data = readdirSync(`./_data/handles`);
// just return the objects?
// without members
data.forEach((file) => {
if (file.endsWith(".json")) {
const buffer = readFileSync(`./_data/handles/${file}`);
const wardenFileData = JSON.parse(buffer.toString());
if (wardenFileData.image) {
const imagePath = wardenFileData.image.slice(2);
wardenFileData.imageUrl = `https://raw.githubusercontent.com/${process.env.GITHUB_REPO_OWNER}/${process.env.REPO}/${process.env.BRANCH_NAME}/_data/handles/${imagePath}`;
}
if (wardenFileData.members) {
teamHandles.push({ ...wardenFileData });
}
}
});

return teamHandles;
}

export async function getUserTeams(username: string): Promise<string[]> {
let teamHandles: string[] = [];

Expand Down
Loading