mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-24 15:05:13 +00:00
upd(config): change the way stripeAgeCheck is handled in config file
This commit is contained in:
parent
dbded3b68d
commit
b3b5872e3e
6 changed files with 26 additions and 20 deletions
|
@ -298,9 +298,10 @@ checkActivityPubGetSignature: false
|
||||||
# maxFileSize: 262144000
|
# maxFileSize: 262144000
|
||||||
|
|
||||||
# enable stripe identity for ID verification
|
# enable stripe identity for ID verification
|
||||||
# stripeVerify: true
|
#stripeAgeCheck:
|
||||||
# stripeKey: sk_
|
# enabled: true
|
||||||
# stripeHookKey: whsec_
|
# key: sk_
|
||||||
|
# hookKey: whsec_
|
||||||
|
|
||||||
# Upload or download file size limits (bytes)
|
# Upload or download file size limits (bytes)
|
||||||
#maxFileSize: 262144000
|
#maxFileSize: 262144000
|
||||||
|
|
|
@ -313,9 +313,10 @@ checkActivityPubGetSignature: false
|
||||||
# maxFileSize: 262144000
|
# maxFileSize: 262144000
|
||||||
|
|
||||||
# enable stripe identity for ID verification
|
# enable stripe identity for ID verification
|
||||||
# stripeVerify: true
|
#stripeAgeCheck:
|
||||||
# stripeKey: sk_
|
# enabled: true
|
||||||
# stripeHookKey: whsec_
|
# key: sk_
|
||||||
|
# hookKey: whsec_
|
||||||
|
|
||||||
# PID File of master process
|
# PID File of master process
|
||||||
#pidFile: /tmp/misskey.pid
|
#pidFile: /tmp/misskey.pid
|
||||||
|
|
|
@ -108,9 +108,11 @@ type Source = {
|
||||||
maxFileSize: number;
|
maxFileSize: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
stripeVerify?: boolean;
|
stripeAgeCheck?: {
|
||||||
stripeKey?: string;
|
enabled: boolean;
|
||||||
stripeHookKey?: string;
|
key: string;
|
||||||
|
hookKey: string;
|
||||||
|
};
|
||||||
|
|
||||||
pidFile: string;
|
pidFile: string;
|
||||||
};
|
};
|
||||||
|
@ -201,9 +203,11 @@ export type Config = {
|
||||||
maxFileSize: number;
|
maxFileSize: number;
|
||||||
} | undefined;
|
} | undefined;
|
||||||
|
|
||||||
stripeVerify: boolean | undefined;
|
stripeAgeCheck: {
|
||||||
stripeKey: string;
|
enabled: boolean | undefined;
|
||||||
stripeHookKey: string;
|
key: string;
|
||||||
|
hookKey: string;
|
||||||
|
} | undefined;
|
||||||
|
|
||||||
pidFile: string;
|
pidFile: string;
|
||||||
};
|
};
|
||||||
|
@ -327,9 +331,7 @@ export function loadConfig(): Config {
|
||||||
perUserNotificationsMaxCount: config.perUserNotificationsMaxCount ?? 500,
|
perUserNotificationsMaxCount: config.perUserNotificationsMaxCount ?? 500,
|
||||||
deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7),
|
deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7),
|
||||||
import: config.import,
|
import: config.import,
|
||||||
stripeVerify: config.stripeVerify ?? false,
|
stripeAgeCheck: config.stripeAgeCheck,
|
||||||
stripeKey: config.stripeKey ?? '',
|
|
||||||
stripeHookKey: config.stripeHookKey ?? '',
|
|
||||||
pidFile: config.pidFile,
|
pidFile: config.pidFile,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ export class ServerService implements OnApplicationShutdown {
|
||||||
fastify.register(this.fileServerService.createServer);
|
fastify.register(this.fileServerService.createServer);
|
||||||
fastify.register(this.activityPubServerService.createServer);
|
fastify.register(this.activityPubServerService.createServer);
|
||||||
// only enable stripe webhook if verification is enabled
|
// only enable stripe webhook if verification is enabled
|
||||||
if (this.config.stripeVerify) fastify.register(this.stripeHookServerService.createServer, { prefix: '/stripe' });
|
if (this.config.stripeAgeCheck?.enabled) fastify.register(this.stripeHookServerService.createServer, { prefix: '/stripe' });
|
||||||
fastify.register(this.nodeinfoServerService.createServer);
|
fastify.register(this.nodeinfoServerService.createServer);
|
||||||
fastify.register(this.wellKnownServerService.createServer);
|
fastify.register(this.wellKnownServerService.createServer);
|
||||||
fastify.register(this.oauth2ProviderService.createServer, { prefix: '/oauth' });
|
fastify.register(this.oauth2ProviderService.createServer, { prefix: '/oauth' });
|
||||||
|
|
|
@ -41,7 +41,9 @@ export class StripeHookServerService {
|
||||||
request: FastifyRequest,
|
request: FastifyRequest,
|
||||||
reply: FastifyReply,
|
reply: FastifyReply,
|
||||||
) {
|
) {
|
||||||
const stripe = new Stripe(this.config.stripeKey);
|
if (!this.config.stripeAgeCheck) return reply.code(400);
|
||||||
|
|
||||||
|
const stripe = new Stripe(this.config.stripeAgeCheck.key);
|
||||||
|
|
||||||
if (request.rawBody == null) {
|
if (request.rawBody == null) {
|
||||||
// Bad request
|
// Bad request
|
||||||
|
@ -63,7 +65,7 @@ export class StripeHookServerService {
|
||||||
// Verify the event came from Stripe
|
// Verify the event came from Stripe
|
||||||
try {
|
try {
|
||||||
const sig = headers['stripe-signature']!;
|
const sig = headers['stripe-signature']!;
|
||||||
event = stripe.webhooks.constructEvent(body, sig, this.config.stripeHookKey);
|
event = stripe.webhooks.constructEvent(body, sig, this.config.stripeAgeCheck.hookKey);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
// On error, log and return the error message
|
// On error, log and return the error message
|
||||||
console.log(`❌ Error message: ${err.message}`);
|
console.log(`❌ Error message: ${err.message}`);
|
||||||
|
|
|
@ -53,7 +53,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
private config: Config,
|
private config: Config,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
if (!this.config.stripeVerify) throw new ApiError(meta.errors.stripeIsDisabled);
|
if (!this.config.stripeAgeCheck?.enabled) throw new ApiError(meta.errors.stripeIsDisabled);
|
||||||
|
|
||||||
const userProfile = await this.usersRepository.findOne({
|
const userProfile = await this.usersRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
@ -61,7 +61,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const stripe = new Stripe(this.config.stripeKey);
|
const stripe = new Stripe(this.config.stripeAgeCheck.key);
|
||||||
|
|
||||||
if (userProfile == null) {
|
if (userProfile == null) {
|
||||||
throw new ApiError(meta.errors.userIsDeleted);
|
throw new ApiError(meta.errors.userIsDeleted);
|
||||||
|
|
Loading…
Reference in a new issue