refactor(api): drop mailing system
This commit is contained in:
parent
dfa570c6e3
commit
205aaa1b0d
@ -1,3 +1 @@
|
||||
GITHUB_TOKEN=?
|
||||
MAIL_PASS=?
|
||||
MAIL_USER=?
|
||||
|
@ -11,14 +11,13 @@
|
||||
"@fastify/cors": "^9.0.1",
|
||||
"@fastify/rate-limit": "^9.1.0",
|
||||
"fastify": "^4.26.1",
|
||||
"node-fetch": "^3.3.2",
|
||||
"nodemailer": "^6.9.9",
|
||||
"node-fetch": "^2.7.0",
|
||||
"octokit": "^3.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tsconfig/node20": "^20.1.2",
|
||||
"@types/node": "^20.11.19",
|
||||
"@types/nodemailer": "^6.4.14",
|
||||
"@types/node-fetch": "2.6.11",
|
||||
"@typescript-eslint/eslint-plugin": "^7.0.1",
|
||||
"@typescript-eslint/parser": "^7.0.1",
|
||||
"eslint": "^8.56.0",
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { FastifyInstance, RouteShorthandOptions } from 'fastify';
|
||||
import { sendMail } from 'services/mailing';
|
||||
|
||||
type PostReportBody = {
|
||||
html?: string;
|
||||
@ -14,30 +13,17 @@ export default (server: FastifyInstance, options: RouteShorthandOptions, done: (
|
||||
{
|
||||
schema: {
|
||||
body: {
|
||||
properties: {
|
||||
html: {
|
||||
type: 'string',
|
||||
},
|
||||
subject: {
|
||||
type: 'string',
|
||||
},
|
||||
text: {
|
||||
type: 'string',
|
||||
},
|
||||
to: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['subject', 'to'],
|
||||
properties: {},
|
||||
required: [],
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
const { html, subject, text, to } = request.body;
|
||||
|
||||
sendMail({ html, text, to, subject });
|
||||
reply.send({ success: true });
|
||||
async (_request, reply) => {
|
||||
reply.status(500).send({
|
||||
success: false,
|
||||
errors: ['This API route is no longer supported in Mozilla Firefox'],
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -1,76 +1 @@
|
||||
import { FastifyInstance, RouteShorthandOptions } from 'fastify';
|
||||
import environment from 'services/environment';
|
||||
import { octokit } from 'services/octokit';
|
||||
|
||||
type PostReportBody = {
|
||||
reason?: string;
|
||||
url: string;
|
||||
userAgent?: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export default (server: FastifyInstance, options: RouteShorthandOptions, done: () => void) => {
|
||||
server.post<{ Body: PostReportBody }>(
|
||||
'/report/',
|
||||
{
|
||||
schema: {
|
||||
body: {
|
||||
properties: {
|
||||
reason: {
|
||||
type: 'string',
|
||||
},
|
||||
url: {
|
||||
type: 'string',
|
||||
},
|
||||
userAgent: {
|
||||
type: 'string',
|
||||
},
|
||||
version: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
required: ['url', 'version'],
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
},
|
||||
async (request, reply) => {
|
||||
try {
|
||||
const issues = await octokit.request('GET /repos/{owner}/{repo}/issues', {
|
||||
owner: environment.github.owner,
|
||||
repo: environment.github.repo,
|
||||
});
|
||||
const url = new URL(request.body.url).hostname
|
||||
.split('.')
|
||||
.slice(-3)
|
||||
.join('.')
|
||||
.replace('www.', '');
|
||||
|
||||
if (issues.data.some((issue) => issue.title.includes(url))) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
await octokit.request('POST /repos/{owner}/{repo}/issues', {
|
||||
assignees: [environment.github.owner],
|
||||
body: [
|
||||
'## Specifications',
|
||||
`- <b>Reason:</b> ${request.body.reason ?? '-'}`,
|
||||
`- <b>URL:</b> ${request.body.url}`,
|
||||
`- <b>User-Agent:</b> ${request.body.userAgent ?? '-'}`,
|
||||
`- <b>Version:</b> ${request.body.version}`,
|
||||
].join('\n'),
|
||||
labels: ['bug'],
|
||||
owner: environment.github.owner,
|
||||
repo: environment.github.repo,
|
||||
title: url,
|
||||
});
|
||||
|
||||
reply.send({ success: true });
|
||||
} catch (error) {
|
||||
reply.send({ errors: [error.message], success: false });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
done();
|
||||
};
|
||||
export { default as default } from 'routes/v2/report';
|
||||
|
@ -4,9 +4,5 @@ export default {
|
||||
repo: 'cookie-dialog-monster',
|
||||
token: process.env.GITHUB_TOKEN ?? '',
|
||||
},
|
||||
mail: {
|
||||
pass: process.env.MAIL_PASS ?? '',
|
||||
user: process.env.MAIL_USER ?? '',
|
||||
},
|
||||
port: (process.env.PORT ? Number(process.env.PORT) : undefined) ?? 8080,
|
||||
};
|
||||
|
@ -1,12 +0,0 @@
|
||||
import nodemailer, { SendMailOptions } from 'nodemailer';
|
||||
import environment from './environment';
|
||||
|
||||
const mailing = nodemailer.createTransport({
|
||||
auth: { pass: environment.mail.pass, user: environment.mail.user },
|
||||
host: 'smtp.zoho.eu',
|
||||
port: 465,
|
||||
secure: true,
|
||||
});
|
||||
|
||||
export const sendMail = (options: SendMailOptions) =>
|
||||
mailing.sendMail({ ...options, from: environment.mail.user }, () => null);
|
140
yarn.lock
140
yarn.lock
@ -908,6 +908,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node-fetch@npm:2.6.11":
|
||||
version: 2.6.11
|
||||
resolution: "@types/node-fetch@npm:2.6.11"
|
||||
dependencies:
|
||||
"@types/node": "npm:*"
|
||||
form-data: "npm:^4.0.0"
|
||||
checksum: 10c0/5283d4e0bcc37a5b6d8e629aee880a4ffcfb33e089f4b903b2981b19c623972d1e64af7c3f9540ab990f0f5c89b9b5dda19c5bcb37a8e177079e93683bfd2f49
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:*, @types/node@npm:^20.11.19":
|
||||
version: 20.11.19
|
||||
resolution: "@types/node@npm:20.11.19"
|
||||
@ -917,15 +927,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/nodemailer@npm:^6.4.14":
|
||||
version: 6.4.14
|
||||
resolution: "@types/nodemailer@npm:6.4.14"
|
||||
dependencies:
|
||||
"@types/node": "npm:*"
|
||||
checksum: 10c0/b5958843576cde76dc532aa7b726182fef8b466fa9fcaf1aa03f89f02e896bec4e28b593ffa1a289a46bd0b7fdf34da0640ab7ef8f0811948016f58f77e16307
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/normalize-package-data@npm:^2.4.0":
|
||||
version: 2.4.4
|
||||
resolution: "@types/normalize-package-data@npm:2.4.4"
|
||||
@ -1305,15 +1306,14 @@ __metadata:
|
||||
"@fastify/rate-limit": "npm:^9.1.0"
|
||||
"@tsconfig/node20": "npm:^20.1.2"
|
||||
"@types/node": "npm:^20.11.19"
|
||||
"@types/nodemailer": "npm:^6.4.14"
|
||||
"@types/node-fetch": "npm:2.6.11"
|
||||
"@typescript-eslint/eslint-plugin": "npm:^7.0.1"
|
||||
"@typescript-eslint/parser": "npm:^7.0.1"
|
||||
eslint: "npm:^8.56.0"
|
||||
eslint-config-prettier: "npm:^9.1.0"
|
||||
eslint-plugin-prettier: "npm:^5.1.3"
|
||||
fastify: "npm:^4.26.1"
|
||||
node-fetch: "npm:^3.3.2"
|
||||
nodemailer: "npm:^6.9.9"
|
||||
node-fetch: "npm:^2.7.0"
|
||||
nodemon: "npm:^3.0.3"
|
||||
octokit: "npm:^3.1.2"
|
||||
rimraf: "npm:^5.0.5"
|
||||
@ -1379,6 +1379,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"asynckit@npm:^0.4.0":
|
||||
version: 0.4.0
|
||||
resolution: "asynckit@npm:0.4.0"
|
||||
checksum: 10c0/d73e2ddf20c4eb9337e1b3df1a0f6159481050a5de457c55b14ea2e5cb6d90bb69e004c9af54737a5ee0917fcf2c9e25de67777bbe58261847846066ba75bc9d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"atomic-sleep@npm:^1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "atomic-sleep@npm:1.0.0"
|
||||
@ -1770,6 +1777,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"combined-stream@npm:^1.0.8":
|
||||
version: 1.0.8
|
||||
resolution: "combined-stream@npm:1.0.8"
|
||||
dependencies:
|
||||
delayed-stream: "npm:~1.0.0"
|
||||
checksum: 10c0/0dbb829577e1b1e839fa82b40c07ffaf7de8a09b935cadd355a73652ae70a88b4320db322f6634a4ad93424292fa80973ac6480986247f1734a1137debf271d5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"commander@npm:11.1.0":
|
||||
version: 11.1.0
|
||||
resolution: "commander@npm:11.1.0"
|
||||
@ -1970,13 +1986,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"data-uri-to-buffer@npm:^4.0.0":
|
||||
version: 4.0.1
|
||||
resolution: "data-uri-to-buffer@npm:4.0.1"
|
||||
checksum: 10c0/20a6b93107597530d71d4cb285acee17f66bcdfc03fd81040921a81252f19db27588d87fc8fc69e1950c55cfb0bf8ae40d0e5e21d907230813eb5d5a7f9eb45b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"debug@npm:2.6.9":
|
||||
version: 2.6.9
|
||||
resolution: "debug@npm:2.6.9"
|
||||
@ -2029,6 +2038,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"delayed-stream@npm:~1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "delayed-stream@npm:1.0.0"
|
||||
checksum: 10c0/d758899da03392e6712f042bec80aa293bbe9e9ff1b2634baae6a360113e708b91326594c8a486d475c69d6259afb7efacdc3537bfcda1c6c648e390ce601b19
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"deprecation@npm:^2.0.0, deprecation@npm:^2.3.1":
|
||||
version: 2.3.1
|
||||
resolution: "deprecation@npm:2.3.1"
|
||||
@ -2534,16 +2550,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"fetch-blob@npm:^3.1.2, fetch-blob@npm:^3.1.4":
|
||||
version: 3.2.0
|
||||
resolution: "fetch-blob@npm:3.2.0"
|
||||
dependencies:
|
||||
node-domexception: "npm:^1.0.0"
|
||||
web-streams-polyfill: "npm:^3.0.3"
|
||||
checksum: 10c0/60054bf47bfa10fb0ba6cb7742acec2f37c1f56344f79a70bb8b1c48d77675927c720ff3191fa546410a0442c998d27ab05e9144c32d530d8a52fbe68f843b69
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"file-entry-cache@npm:^6.0.1":
|
||||
version: 6.0.1
|
||||
resolution: "file-entry-cache@npm:6.0.1"
|
||||
@ -2631,12 +2637,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"formdata-polyfill@npm:^4.0.10":
|
||||
version: 4.0.10
|
||||
resolution: "formdata-polyfill@npm:4.0.10"
|
||||
"form-data@npm:^4.0.0":
|
||||
version: 4.0.0
|
||||
resolution: "form-data@npm:4.0.0"
|
||||
dependencies:
|
||||
fetch-blob: "npm:^3.1.2"
|
||||
checksum: 10c0/5392ec484f9ce0d5e0d52fb5a78e7486637d516179b0eb84d81389d7eccf9ca2f663079da56f761355c0a65792810e3b345dc24db9a8bbbcf24ef3c8c88570c6
|
||||
asynckit: "npm:^0.4.0"
|
||||
combined-stream: "npm:^1.0.8"
|
||||
mime-types: "npm:^2.1.12"
|
||||
checksum: 10c0/cb6f3ac49180be03ff07ba3ff125f9eba2ff0b277fb33c7fc47569fc5e616882c5b1c69b9904c4c4187e97dd0419dd03b134174756f296dec62041e6527e2c6e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -3752,7 +3760,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mime-types@npm:~2.1.34":
|
||||
"mime-types@npm:^2.1.12, mime-types@npm:~2.1.34":
|
||||
version: 2.1.35
|
||||
resolution: "mime-types@npm:2.1.35"
|
||||
dependencies:
|
||||
@ -4005,21 +4013,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-domexception@npm:^1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "node-domexception@npm:1.0.0"
|
||||
checksum: 10c0/5e5d63cda29856402df9472335af4bb13875e1927ad3be861dc5ebde38917aecbf9ae337923777af52a48c426b70148815e890a5d72760f1b4d758cc671b1a2b
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-fetch@npm:^3.3.2":
|
||||
version: 3.3.2
|
||||
resolution: "node-fetch@npm:3.3.2"
|
||||
"node-fetch@npm:^2.7.0":
|
||||
version: 2.7.0
|
||||
resolution: "node-fetch@npm:2.7.0"
|
||||
dependencies:
|
||||
data-uri-to-buffer: "npm:^4.0.0"
|
||||
fetch-blob: "npm:^3.1.4"
|
||||
formdata-polyfill: "npm:^4.0.10"
|
||||
checksum: 10c0/f3d5e56190562221398c9f5750198b34cf6113aa304e34ee97c94fd300ec578b25b2c2906edba922050fce983338fde0d5d34fcb0fc3336ade5bd0e429ad7538
|
||||
whatwg-url: "npm:^5.0.0"
|
||||
peerDependencies:
|
||||
encoding: ^0.1.0
|
||||
peerDependenciesMeta:
|
||||
encoding:
|
||||
optional: true
|
||||
checksum: 10c0/b55786b6028208e6fbe594ccccc213cab67a72899c9234eb59dba51062a299ea853210fcf526998eaa2867b0963ad72338824450905679ff0fa304b8c5093ae8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -4043,13 +4047,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"nodemailer@npm:^6.9.9":
|
||||
version: 6.9.9
|
||||
resolution: "nodemailer@npm:6.9.9"
|
||||
checksum: 10c0/ba72da4ca8a003921c86f3d132d64d9bb86c1a3d79d248664b3de28f6a7a621f0476273ad7cf3ecc48d3b78a66ae4ec62b7c4c8ab6f07d9ca26d4bad4d08802e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"nodemon@npm:^3.0.3":
|
||||
version: 3.0.3
|
||||
resolution: "nodemon@npm:3.0.3"
|
||||
@ -5581,6 +5578,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tr46@npm:~0.0.3":
|
||||
version: 0.0.3
|
||||
resolution: "tr46@npm:0.0.3"
|
||||
checksum: 10c0/047cb209a6b60c742f05c9d3ace8fa510bff609995c129a37ace03476a9b12db4dbf975e74600830ef0796e18882b2381fb5fb1f6b4f96b832c374de3ab91a11
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"trim-newlines@npm:^3.0.0":
|
||||
version: 3.0.1
|
||||
resolution: "trim-newlines@npm:3.0.1"
|
||||
@ -5844,13 +5848,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"web-streams-polyfill@npm:^3.0.3":
|
||||
version: 3.3.2
|
||||
resolution: "web-streams-polyfill@npm:3.3.2"
|
||||
checksum: 10c0/623c2fced2ef77d5afdbc43acef64b8af609a32125b691eae286d534a36004c8a71030f0e78068516774a97fd90dbfb3726b10fd569a2d158e60c83a539c489e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"web@workspace:packages/web":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "web@workspace:packages/web"
|
||||
@ -5862,6 +5859,23 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"webidl-conversions@npm:^3.0.0":
|
||||
version: 3.0.1
|
||||
resolution: "webidl-conversions@npm:3.0.1"
|
||||
checksum: 10c0/5612d5f3e54760a797052eb4927f0ddc01383550f542ccd33d5238cfd65aeed392a45ad38364970d0a0f4fea32e1f4d231b3d8dac4a3bdd385e5cf802ae097db
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"whatwg-url@npm:^5.0.0":
|
||||
version: 5.0.0
|
||||
resolution: "whatwg-url@npm:5.0.0"
|
||||
dependencies:
|
||||
tr46: "npm:~0.0.3"
|
||||
webidl-conversions: "npm:^3.0.0"
|
||||
checksum: 10c0/1588bed84d10b72d5eec1d0faa0722ba1962f1821e7539c535558fb5398d223b0c50d8acab950b8c488b4ba69043fd833cc2697056b167d8ad46fac3995a55d5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"which@npm:^2.0.1":
|
||||
version: 2.0.2
|
||||
resolution: "which@npm:2.0.2"
|
||||
|
Loading…
Reference in New Issue
Block a user