Merge pull request #934 from fosscord/master
Merge master into dev/endpoints-in-ping
This commit is contained in:
commit
0b89db8031
@ -23,8 +23,6 @@ This repository contains:
|
|||||||
- [HTTP CDN Server](/src/cdn)
|
- [HTTP CDN Server](/src/cdn)
|
||||||
- [Utility and Database Models](/src/util)
|
- [Utility and Database Models](/src/util)
|
||||||
|
|
||||||
## [Resources](https://docs.fosscord.com/resources/)
|
## [Contributing](https://docs.fosscord.com/contributing/)
|
||||||
|
|
||||||
- [Contributing](https://docs.fosscord.com/contributing/server/)
|
## [Setup](https://docs.fosscord.com/setup/server/)
|
||||||
|
|
||||||
## [Setup](https://docs.fosscord.com/server/setup/)
|
|
||||||
|
@ -65,6 +65,12 @@ const doPatch = (content) => {
|
|||||||
//content = content.replaceAll(/DiscordTag/g, "FosscordTag");
|
//content = content.replaceAll(/DiscordTag/g, "FosscordTag");
|
||||||
content = content.replaceAll(/\*Discord\*/g, `*${INSTANCE_NAME}*`);
|
content = content.replaceAll(/\*Discord\*/g, `*${INSTANCE_NAME}*`);
|
||||||
|
|
||||||
|
// Replace window title
|
||||||
|
content = content.replaceAll(
|
||||||
|
":c.base;",
|
||||||
|
`:(c.base == 'Discord' ? '${INSTANCE_NAME}' : c.base);`,
|
||||||
|
);
|
||||||
|
|
||||||
//server -> guild
|
//server -> guild
|
||||||
const serverVariations = [
|
const serverVariations = [
|
||||||
['"Server"', '"Guild"'],
|
['"Server"', '"Guild"'],
|
||||||
@ -186,6 +192,12 @@ const processFile = async (name) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const print = (x) => {
|
||||||
|
process.stdout.write(
|
||||||
|
`${x}${" ".repeat(process.stdout.columns - x.length)}\r`,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
|
|
||||||
@ -198,9 +210,7 @@ const processFile = async (name) => {
|
|||||||
while (INDEX_SCRIPTS.length > 0) {
|
while (INDEX_SCRIPTS.length > 0) {
|
||||||
const asset = INDEX_SCRIPTS.shift();
|
const asset = INDEX_SCRIPTS.shift();
|
||||||
|
|
||||||
process.stdout.write(
|
print(`Scraping asset ${asset}. Remaining: ${INDEX_SCRIPTS.length}`);
|
||||||
`Scraping asset ${asset}. Remaining: ${INDEX_SCRIPTS.length} \r`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const newAssets = await processFile(asset);
|
const newAssets = await processFile(asset);
|
||||||
assets.push(...newAssets);
|
assets.push(...newAssets);
|
||||||
@ -218,8 +228,8 @@ const processFile = async (name) => {
|
|||||||
while (CACHE_MISSES.length > 0) {
|
while (CACHE_MISSES.length > 0) {
|
||||||
const asset = CACHE_MISSES.shift();
|
const asset = CACHE_MISSES.shift();
|
||||||
|
|
||||||
process.stdout.write(
|
print(
|
||||||
`Scraping cache misses ${asset}. Remaining: ${CACHE_MISSES.length} \r`,
|
`Scraping cache misses ${asset}. Remaining: ${CACHE_MISSES.length}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existsSync(path.join(CACHE_PATH, `${asset}`))) {
|
if (existsSync(path.join(CACHE_PATH, `${asset}`))) {
|
||||||
@ -236,9 +246,7 @@ const processFile = async (name) => {
|
|||||||
while (existing.length > 0) {
|
while (existing.length > 0) {
|
||||||
var file = existing.shift();
|
var file = existing.shift();
|
||||||
|
|
||||||
process.stdout.write(
|
print(`Patching existing ${file}. Remaining: ${existing.length}.`);
|
||||||
`Patching existing ${file}. Remaining: ${existing.length}. \r`,
|
|
||||||
);
|
|
||||||
|
|
||||||
var text = await fs.readFile(path.join(CACHE_PATH, file));
|
var text = await fs.readFile(path.join(CACHE_PATH, file));
|
||||||
if (file.includes(".js") || file.includes(".css")) {
|
if (file.includes(".js") || file.includes(".css")) {
|
||||||
@ -273,7 +281,7 @@ const processFile = async (name) => {
|
|||||||
: 1;
|
: 1;
|
||||||
const finishTime = averageRate * (assets.length - i);
|
const finishTime = averageRate * (assets.length - i);
|
||||||
|
|
||||||
process.stdout.write(
|
print(
|
||||||
`Caching asset ${asset}. ` +
|
`Caching asset ${asset}. ` +
|
||||||
`${i}/${assets.length - 1} = ${Math.floor(
|
`${i}/${assets.length - 1} = ${Math.floor(
|
||||||
(i / (assets.length - 1)) * 100,
|
(i / (assets.length - 1)) * 100,
|
||||||
@ -282,8 +290,6 @@ const processFile = async (name) => {
|
|||||||
// Date.now() + finishTime,
|
// Date.now() + finishTime,
|
||||||
// ).toLocaleTimeString()}`,
|
// ).toLocaleTimeString()}`,
|
||||||
);
|
);
|
||||||
//not adding to the previous mess, incase the finish time is added back or something
|
|
||||||
process.stdout.write(" \r");
|
|
||||||
|
|
||||||
promises.push(processFile(asset));
|
promises.push(processFile(asset));
|
||||||
// await processFile(asset);
|
// await processFile(asset);
|
||||||
|
@ -223,6 +223,7 @@ export async function postHandleMessage(message: Message) {
|
|||||||
data.embeds.push(embed);
|
data.embeds.push(embed);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(`[Embeds] Error while generating embed`, e);
|
||||||
Sentry.captureException(e, (scope) => {
|
Sentry.captureException(e, (scope) => {
|
||||||
scope.clear();
|
scope.clear();
|
||||||
scope.setContext("request", { url });
|
scope.setContext("request", { url });
|
||||||
|
@ -3,6 +3,7 @@ import fetch, { Response } from "node-fetch";
|
|||||||
import * as cheerio from "cheerio";
|
import * as cheerio from "cheerio";
|
||||||
import probe from "probe-image-size";
|
import probe from "probe-image-size";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
import { yellow } from "picocolors";
|
||||||
|
|
||||||
export const DEFAULT_FETCH_OPTIONS: any = {
|
export const DEFAULT_FETCH_OPTIONS: any = {
|
||||||
redirect: "follow",
|
redirect: "follow",
|
||||||
@ -16,6 +17,8 @@ export const DEFAULT_FETCH_OPTIONS: any = {
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let hasWarnedAboutImagor = false;
|
||||||
|
|
||||||
export const getProxyUrl = (
|
export const getProxyUrl = (
|
||||||
url: URL,
|
url: URL,
|
||||||
width: number,
|
width: number,
|
||||||
@ -41,11 +44,17 @@ export const getProxyUrl = (
|
|||||||
return `${imagorServerUrl}/${hash}/${path}`;
|
return `${imagorServerUrl}/${hash}/${path}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Imagor documentation
|
if (!hasWarnedAboutImagor) {
|
||||||
console.log(
|
hasWarnedAboutImagor = true;
|
||||||
"Imagor has not been set up correctly. docs.fosscord.com/set/up/a/page/about/this",
|
console.log(
|
||||||
);
|
"[Embeds]",
|
||||||
return "";
|
yellow(
|
||||||
|
"Imagor has not been set up correctly. https://docs.fosscord.com/setup/server/configuration/imagor/",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return url.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => {
|
const getMeta = ($: cheerio.CheerioAPI, name: string): string | undefined => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user