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
|
||||
|
||||
# enable stripe identity for ID verification
|
||||
# stripeVerify: true
|
||||
# stripeKey: sk_
|
||||
# stripeHookKey: whsec_
|
||||
#stripeAgeCheck:
|
||||
# enabled: true
|
||||
# key: sk_
|
||||
# hookKey: whsec_
|
||||
|
||||
# Upload or download file size limits (bytes)
|
||||
#maxFileSize: 262144000
|
||||
|
|
|
@ -313,9 +313,10 @@ checkActivityPubGetSignature: false
|
|||
# maxFileSize: 262144000
|
||||
|
||||
# enable stripe identity for ID verification
|
||||
# stripeVerify: true
|
||||
# stripeKey: sk_
|
||||
# stripeHookKey: whsec_
|
||||
#stripeAgeCheck:
|
||||
# enabled: true
|
||||
# key: sk_
|
||||
# hookKey: whsec_
|
||||
|
||||
# PID File of master process
|
||||
#pidFile: /tmp/misskey.pid
|
||||
|
|
|
@ -108,9 +108,11 @@ type Source = {
|
|||
maxFileSize: number;
|
||||
};
|
||||
|
||||
stripeVerify?: boolean;
|
||||
stripeKey?: string;
|
||||
stripeHookKey?: string;
|
||||
stripeAgeCheck?: {
|
||||
enabled: boolean;
|
||||
key: string;
|
||||
hookKey: string;
|
||||
};
|
||||
|
||||
pidFile: string;
|
||||
};
|
||||
|
@ -201,9 +203,11 @@ export type Config = {
|
|||
maxFileSize: number;
|
||||
} | undefined;
|
||||
|
||||
stripeVerify: boolean | undefined;
|
||||
stripeKey: string;
|
||||
stripeHookKey: string;
|
||||
stripeAgeCheck: {
|
||||
enabled: boolean | undefined;
|
||||
key: string;
|
||||
hookKey: string;
|
||||
} | undefined;
|
||||
|
||||
pidFile: string;
|
||||
};
|
||||
|
@ -327,9 +331,7 @@ export function loadConfig(): Config {
|
|||
perUserNotificationsMaxCount: config.perUserNotificationsMaxCount ?? 500,
|
||||
deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7),
|
||||
import: config.import,
|
||||
stripeVerify: config.stripeVerify ?? false,
|
||||
stripeKey: config.stripeKey ?? '',
|
||||
stripeHookKey: config.stripeHookKey ?? '',
|
||||
stripeAgeCheck: config.stripeAgeCheck,
|
||||
pidFile: config.pidFile,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ export class ServerService implements OnApplicationShutdown {
|
|||
fastify.register(this.fileServerService.createServer);
|
||||
fastify.register(this.activityPubServerService.createServer);
|
||||
// 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.wellKnownServerService.createServer);
|
||||
fastify.register(this.oauth2ProviderService.createServer, { prefix: '/oauth' });
|
||||
|
|
|
@ -41,7 +41,9 @@ export class StripeHookServerService {
|
|||
request: FastifyRequest,
|
||||
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) {
|
||||
// Bad request
|
||||
|
@ -63,7 +65,7 @@ export class StripeHookServerService {
|
|||
// Verify the event came from Stripe
|
||||
try {
|
||||
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) {
|
||||
// On error, log and return the error message
|
||||
console.log(`❌ Error message: ${err.message}`);
|
||||
|
|
|
@ -53,7 +53,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
private config: Config,
|
||||
) {
|
||||
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({
|
||||
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) {
|
||||
throw new ApiError(meta.errors.userIsDeleted);
|
||||
|
|
Loading…
Reference in a new issue