feat(discord): support show reading status with Discord Rich Presence, closes #1538 (#2998)

This commit is contained in:
Huang Xin
2026-01-19 17:42:19 +01:00
committed by GitHub
parent 1704736bc8
commit d9a6cffe78
50 changed files with 794 additions and 85 deletions
+13 -8
View File
@@ -2,13 +2,17 @@ import { s3Storage } from './s3';
import { r2Storage } from './r2';
import { getStorageType } from './storage';
export const getDownloadSignedUrl = async (fileKey: string, expiresIn: number) => {
export const getDownloadSignedUrl = async (
fileKey: string,
expiresIn: number,
bucketName?: string,
) => {
const storageType = getStorageType();
if (storageType === 'r2') {
const bucketName = process.env['R2_BUCKET_NAME'] || '';
bucketName = bucketName || process.env['R2_BUCKET_NAME'] || '';
return await r2Storage.getDownloadSignedUrl(bucketName, fileKey, expiresIn);
} else {
const bucketName = process.env['S3_BUCKET_NAME'] || '';
bucketName = bucketName || process.env['S3_BUCKET_NAME'] || '';
return await s3Storage.getDownloadSignedUrl(bucketName, fileKey, expiresIn);
}
};
@@ -17,24 +21,25 @@ export const getUploadSignedUrl = async (
fileKey: string,
contentLength: number,
expiresIn: number,
bucketName?: string,
) => {
const storageType = getStorageType();
if (storageType === 'r2') {
const bucketName = process.env['R2_BUCKET_NAME'] || '';
bucketName = bucketName || process.env['R2_BUCKET_NAME'] || '';
return await r2Storage.getUploadSignedUrl(bucketName, fileKey, contentLength, expiresIn);
} else {
const bucketName = process.env['S3_BUCKET_NAME'] || '';
bucketName = bucketName || process.env['S3_BUCKET_NAME'] || '';
return await s3Storage.getUploadSignedUrl(bucketName, fileKey, contentLength, expiresIn);
}
};
export const deleteObject = async (fileKey: string) => {
export const deleteObject = async (fileKey: string, bucketName?: string) => {
const storageType = getStorageType();
if (storageType === 'r2') {
const bucketName = process.env['R2_BUCKET_NAME'] || '';
bucketName = bucketName || process.env['R2_BUCKET_NAME'] || '';
return await r2Storage.deleteObject(bucketName, fileKey);
} else {
const bucketName = process.env['S3_BUCKET_NAME'] || '';
bucketName = bucketName || process.env['S3_BUCKET_NAME'] || '';
return await s3Storage.deleteObject(bucketName, fileKey);
}
};