[Various] New env JS file, AuthorGen

This commit is contained in:
Ducko 2021-07-01 20:41:16 +01:00 committed by Alyxia Sother
parent f2ac90299c
commit ea51962e77
No known key found for this signature in database
GPG Key ID: 355968D14144B739
4 changed files with 50 additions and 11 deletions

5
.gitignore vendored
View File

@ -1,9 +1,6 @@
node_modules
.cache
clones
src/gh_pat.json
# dist
src/env.js
devDist
devTemp

View File

@ -2,4 +2,13 @@
Builder for Module Store v2.
**To run this yourself, you need to [get your own GitHub Personal Access Token](https://docs.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) and export it in `src/gh_pat.js`.**
To run this yourself, you **need** to:
1. [Get your own GitHub Personal Access Token](https://docs.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)
2. Get a Discord bot token
3. Make a `src/env.js` file like:
```js
export default {
github: '<your github pat>',
discord: '<your discord bot token>
}
```

25
src/authorGen.js Normal file
View File

@ -0,0 +1,25 @@
import Env from './env.js';
import axios from 'axios';
const userCache = {};
const getUser = async (id) => userCache[id] || (userCache[id] = (await axios.get(`https://discord.com/api/v9/users/${id}`, {
headers: {
'Authorization': `Bot ${Env.discord}`
}
})).data);
export default async (id) => {
const user = await getUser(id);
console.log(user);
return { // Use semi-minified keys as to avoid size
i: id, // id
n: `${user.username}#${user.discriminator}`, // name
a: user.avatar // avatar
}
};

View File

@ -1,23 +1,23 @@
import ModuleRepos from './modules/index.js';
import AutoTag from './autoTag.js';
import WebhookSend from './webhook.js';
import ImageCDN from './imageCdn.js';
import authorGen from './authorGen.js';
import Parcel from 'parcel-bundler';
import axios from 'axios';
import glob from 'glob';
import { rmSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, existsSync, rmdirSync } from 'fs';
import { rmSync, mkdirSync, readFileSync, writeFileSync, copyFileSync, existsSync } from 'fs';
import { createHash } from 'crypto';
import { dirname, sep } from 'path';
import { fileURLToPath } from 'url';
let file;
let githubPAT;
try {
file = JSON.parse(readFileSync('./gh_pat.json'));
githubPAT = file.token;
import Env from './env.js';
} catch (error) {
if (error.code !== 'ENOENT') throw error;
githubPAT = process.env.GHTOKEN;
@ -80,7 +80,7 @@ const getGithubInfo = async (repo) => {
const info = (await axios.get(`https://api.github.com/repos/${repo}`, {
headers: {
'Authorization': `token ${githubPAT}`
'Authorization': `token ${Env.github}`
}
})).data;
@ -222,6 +222,14 @@ for (const parentRepo of ModuleRepos) {
manifestJson.images = await ImageCDN(manifestJson);
manifestJson.authors = await Promise.all(manifestJson.authors.map(async (x) => {
if (x.match(/^[0-9]{17,18}$/)) {
return await authorGen(x);
}
return x;
}));
moduleJson.modules.push(manifestJson);
console.timeEnd(repo.slice(0, 2).join(' @ ')+`${repo[2] ? ` ${repo[2]}` : ''}`);