Skip to content

Commit

Permalink
Fastify (#9106)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* fix

* Update SignupApiService.ts

* wip

* wip

* Update ClientServerService.ts

* wip

* wip

* wip

* Update WellKnownServerService.ts

* wip

* wip

* update des

* wip

* Update ApiServerService.ts

* wip

* update deps

* Update WellKnownServerService.ts

* wip

* update deps

* Update ApiCallService.ts

* Update ApiCallService.ts

* Update ApiServerService.ts
  • Loading branch information
syuilo committed Dec 3, 2022
1 parent 2db9f6e commit 3a7182b
Show file tree
Hide file tree
Showing 40 changed files with 1,669 additions and 1,995 deletions.
38 changes: 10 additions & 28 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@
"@tensorflow/tfjs-node": "4.1.0"
},
"dependencies": {
"@bull-board/api": "4.3.1",
"@bull-board/koa": "4.3.1",
"@bull-board/ui": "4.3.1",
"@discordapp/twemoji": "14.0.2",
"@elastic/elasticsearch": "7.17.0",
"@koa/cors": "3.3.0",
"@koa/multer": "3.0.0",
"@koa/router": "9.0.1",
"@fastify/accepts": "4.0.1",
"@fastify/cors": "8.2.0",
"@fastify/multipart": "7.3.0",
"@fastify/static": "6.5.0",
"@fastify/view": "7.1.2",
"@nestjs/common": "9.2.0",
"@nestjs/core": "9.2.0",
"@nestjs/testing": "9.2.0",
"@peertube/http-signature": "1.7.0",
"@sinonjs/fake-timers": "10.0.0",
"@syuilo/aiscript": "0.11.1",
"accepts": "^1.3.8",
"ajv": "8.11.2",
"archiver": "5.3.1",
"autobind-decorator": "2.4.0",
Expand All @@ -54,6 +53,7 @@
"date-fns": "2.29.3",
"deep-email-validator": "0.1.21",
"escape-regexp": "0.0.1",
"fastify": "4.10.0",
"feed": "4.2.2",
"file-type": "18.0.0",
"fluent-ffmpeg": "2.1.2",
Expand All @@ -69,20 +69,10 @@
"json5-loader": "4.0.1",
"jsonld": "8.1.0",
"jsrsasign": "10.6.1",
"koa": "2.13.4",
"koa-bodyparser": "4.3.0",
"koa-favicon": "2.1.0",
"koa-json-body": "5.3.0",
"koa-logger": "3.2.1",
"koa-mount": "4.0.0",
"koa-send": "5.0.1",
"koa-slow": "2.1.0",
"koa-views": "7.0.2",
"mfm-js": "0.23.0",
"mime-types": "2.1.35",
"misskey-js": "0.0.14",
"ms": "3.0.0-canary.1",
"multer": "1.4.4",
"nested-property": "4.0.0",
"node-fetch": "3.3.0",
"nodemailer": "6.8.0",
Expand Down Expand Up @@ -129,6 +119,7 @@
"ulid": "2.3.0",
"unzipper": "0.10.11",
"uuid": "9.0.0",
"vary": "1.1.2",
"web-push": "3.5.0",
"websocket": "1.0.34",
"ws": "8.11.0",
Expand All @@ -138,6 +129,7 @@
"@redocly/openapi-core": "1.0.0-beta.114",
"@swc/core": "1.3.20",
"@swc/jest": "0.2.23",
"@types/accepts": "1.3.5",
"@types/archiver": "5.3.1",
"@types/bcryptjs": "2.4.2",
"@types/bull": "4.10.0",
Expand All @@ -149,17 +141,6 @@
"@types/jsdom": "20.0.1",
"@types/jsonld": "1.5.8",
"@types/jsrsasign": "10.5.4",
"@types/koa": "2.13.5",
"@types/koa-bodyparser": "4.3.8",
"@types/koa-cors": "0.0.2",
"@types/koa-favicon": "2.0.21",
"@types/koa-logger": "3.1.2",
"@types/koa-mount": "4.0.1",
"@types/koa-send": "4.1.3",
"@types/koa-views": "7.0.0",
"@types/koa__cors": "3.3.0",
"@types/koa__multer": "2.0.4",
"@types/koa__router": "8.0.11",
"@types/mime-types": "2.1.1",
"@types/node": "18.11.9",
"@types/node-fetch": "3.0.3",
Expand All @@ -182,6 +163,7 @@
"@types/tmp": "0.2.3",
"@types/unzipper": "0.10.5",
"@types/uuid": "8.3.4",
"@types/vary": "1.1.0",
"@types/web-push": "3.3.2",
"@types/websocket": "1.0.5",
"@types/ws": "8.5.3",
Expand Down
15 changes: 0 additions & 15 deletions packages/backend/src/@types/koa-json-body.d.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/backend/src/@types/koa-slow.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/backend/src/boot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ if (!envOption.quiet) {
process.on('uncaughtException', err => {
try {
logger.error(err);
console.trace(err);
} catch { }
});

Expand Down
30 changes: 21 additions & 9 deletions packages/backend/src/core/CaptchaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ export class CaptchaService {
return await res.json() as CaptchaResponse;
}

public async verifyRecaptcha(secret: string, response: string): Promise<void> {
const result = await this.getCaptchaResponse('https://www.recaptcha.net/recaptcha/api/siteverify', secret, response).catch(e => {
throw `recaptcha-request-failed: ${e}`;
public async verifyRecaptcha(secret: string, response: string | null | undefined): Promise<void> {
if (response == null) {
throw 'recaptcha-failed: no response provided';
}

const result = await this.getCaptchaResponse('https://www.recaptcha.net/recaptcha/api/siteverify', secret, response).catch(err => {
throw `recaptcha-request-failed: ${err}`;
});

if (result.success !== true) {
Expand All @@ -56,9 +60,13 @@ export class CaptchaService {
}
}

public async verifyHcaptcha(secret: string, response: string): Promise<void> {
const result = await this.getCaptchaResponse('https://hcaptcha.com/siteverify', secret, response).catch(e => {
throw `hcaptcha-request-failed: ${e}`;
public async verifyHcaptcha(secret: string, response: string | null | undefined): Promise<void> {
if (response == null) {
throw 'hcaptcha-failed: no response provided';
}

const result = await this.getCaptchaResponse('https://hcaptcha.com/siteverify', secret, response).catch(err => {
throw `hcaptcha-request-failed: ${err}`;
});

if (result.success !== true) {
Expand All @@ -67,9 +75,13 @@ export class CaptchaService {
}
}

public async verifyTurnstile(secret: string, response: string): Promise<void> {
const result = await this.getCaptchaResponse('https://challenges.cloudflare.com/turnstile/v0/siteverify', secret, response).catch(e => {
throw `turnstile-request-failed: ${e}`;
public async verifyTurnstile(secret: string, response: string | null | undefined): Promise<void> {
if (response == null) {
throw 'turnstile-failed: no response provided';
}

const result = await this.getCaptchaResponse('https://challenges.cloudflare.com/turnstile/v0/siteverify', secret, response).catch(err => {
throw `turnstile-request-failed: ${err}`;
});

if (result.success !== true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ export class ApRendererService {
* @param last URL of last page (optional)
* @param orderedItems attached objects (optional)
*/
public renderOrderedCollection(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: Record<string, unknown>[]) {
public renderOrderedCollection(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: IObject[]) {
const page: any = {
id,
type: 'OrderedCollection',
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const envOption = {
verbose: false,
withLogTime: false,
quiet: false,
slow: false,
};

for (const key of Object.keys(envOption) as (keyof typeof envOption)[]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/misc/create-temp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createTempDir(): Promise<[string, () => void]> {
(e, path, cleanup) => {
if (e) return rej(e);
res([path, cleanup]);
}
},
);
});
}
11 changes: 11 additions & 0 deletions packages/backend/src/misc/fastify-reply-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://www.fastify.io/docs/latest/Reference/Reply/#async-await-and-promises
export class FastifyReplyError extends Error {
public message: string;
public statusCode: number;

constructor(statusCode: number, message: string) {
super(message);
this.message = message;
this.statusCode = statusCode;
}
}

0 comments on commit 3a7182b

Please sign in to comment.