mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-25 03:35:12 +00:00
fix(server): Force the extention of exported file (#10630)
* fix(server): Force the extention of exported file * update changelog.md
This commit is contained in:
parent
14f30afd3c
commit
168fe0e376
8 changed files with 24 additions and 11 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -11,6 +11,16 @@
|
||||||
-
|
-
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
## 13.x.x (unreleased)
|
||||||
|
|
||||||
|
### General
|
||||||
|
-
|
||||||
|
|
||||||
|
### Client
|
||||||
|
-
|
||||||
|
|
||||||
|
### Server
|
||||||
|
- エクスポートデータの拡張子がunknownになる問題を修正
|
||||||
|
|
||||||
## 13.11.3
|
## 13.11.3
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,8 @@ type AddFileArgs = {
|
||||||
uri?: string | null;
|
uri?: string | null;
|
||||||
/** Mark file as sensitive */
|
/** Mark file as sensitive */
|
||||||
sensitive?: boolean | null;
|
sensitive?: boolean | null;
|
||||||
|
/** Extension to force */
|
||||||
|
ext?: string | null;
|
||||||
|
|
||||||
requestIp?: string | null;
|
requestIp?: string | null;
|
||||||
requestHeaders?: Record<string, string> | null;
|
requestHeaders?: Record<string, string> | null;
|
||||||
|
@ -125,7 +127,7 @@ export class DriveService {
|
||||||
/***
|
/***
|
||||||
* Save file
|
* Save file
|
||||||
* @param path Path for original
|
* @param path Path for original
|
||||||
* @param name Name for original
|
* @param name Name for original (should be extention corrected)
|
||||||
* @param type Content-Type for original
|
* @param type Content-Type for original
|
||||||
* @param hash Hash for original
|
* @param hash Hash for original
|
||||||
* @param size Size for original
|
* @param size Size for original
|
||||||
|
@ -151,7 +153,7 @@ export class DriveService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拡張子からContent-Typeを設定してそうな挙動を示すオブジェクトストレージ (upcloud?) も存在するので、
|
// 拡張子からContent-Typeを設定してそうな挙動を示すオブジェクトストレージ (upcloud?) も存在するので、
|
||||||
// 許可されているファイル形式でしか拡張子をつけない
|
// 許可されているファイル形式でしかURLに拡張子をつけない
|
||||||
if (!FILE_TYPE_BROWSERSAFE.includes(type)) {
|
if (!FILE_TYPE_BROWSERSAFE.includes(type)) {
|
||||||
ext = '';
|
ext = '';
|
||||||
}
|
}
|
||||||
|
@ -173,7 +175,7 @@ export class DriveService {
|
||||||
//#region Uploads
|
//#region Uploads
|
||||||
this.registerLogger.info(`uploading original: ${key}`);
|
this.registerLogger.info(`uploading original: ${key}`);
|
||||||
const uploads = [
|
const uploads = [
|
||||||
this.upload(key, fs.createReadStream(path), type, ext, name),
|
this.upload(key, fs.createReadStream(path), type, null, name),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (alts.webpublic) {
|
if (alts.webpublic) {
|
||||||
|
@ -189,7 +191,7 @@ export class DriveService {
|
||||||
thumbnailUrl = `${ baseUrl }/${ thumbnailKey }`;
|
thumbnailUrl = `${ baseUrl }/${ thumbnailKey }`;
|
||||||
|
|
||||||
this.registerLogger.info(`uploading thumbnail: ${thumbnailKey}`);
|
this.registerLogger.info(`uploading thumbnail: ${thumbnailKey}`);
|
||||||
uploads.push(this.upload(thumbnailKey, alts.thumbnail.data, alts.thumbnail.type, alts.thumbnail.ext));
|
uploads.push(this.upload(thumbnailKey, alts.thumbnail.data, alts.thumbnail.type, alts.thumbnail.ext, `${name}.thumbnail`));
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(uploads);
|
await Promise.all(uploads);
|
||||||
|
@ -443,6 +445,7 @@ export class DriveService {
|
||||||
sensitive = null,
|
sensitive = null,
|
||||||
requestIp = null,
|
requestIp = null,
|
||||||
requestHeaders = null,
|
requestHeaders = null,
|
||||||
|
ext = null,
|
||||||
}: AddFileArgs): Promise<DriveFile> {
|
}: AddFileArgs): Promise<DriveFile> {
|
||||||
let skipNsfwCheck = false;
|
let skipNsfwCheck = false;
|
||||||
const instance = await this.metaService.fetch();
|
const instance = await this.metaService.fetch();
|
||||||
|
@ -474,7 +477,7 @@ export class DriveService {
|
||||||
// DriveFile.nameは256文字, validateFileNameは200文字制限であるため、
|
// DriveFile.nameは256文字, validateFileNameは200文字制限であるため、
|
||||||
// extを付加してデータベースの文字数制限に当たることはまずない
|
// extを付加してデータベースの文字数制限に当たることはまずない
|
||||||
(name && this.driveFileEntityService.validateFileName(name)) ? name : 'untitled',
|
(name && this.driveFileEntityService.validateFileName(name)) ? name : 'untitled',
|
||||||
info.type.ext,
|
ext ?? info.type.ext,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (user && !force) {
|
if (user && !force) {
|
||||||
|
|
|
@ -106,7 +106,7 @@ export class ExportBlockingProcessorService {
|
||||||
this.logger.succ(`Exported to: ${path}`);
|
this.logger.succ(`Exported to: ${path}`);
|
||||||
|
|
||||||
const fileName = 'blocking-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
const fileName = 'blocking-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
||||||
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true });
|
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true, ext: 'csv' });
|
||||||
|
|
||||||
this.logger.succ(`Exported to: ${driveFile.id}`);
|
this.logger.succ(`Exported to: ${driveFile.id}`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -121,7 +121,7 @@ export class ExportFavoritesProcessorService {
|
||||||
this.logger.succ(`Exported to: ${path}`);
|
this.logger.succ(`Exported to: ${path}`);
|
||||||
|
|
||||||
const fileName = 'favorites-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.json';
|
const fileName = 'favorites-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.json';
|
||||||
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true });
|
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true, ext: 'json' });
|
||||||
|
|
||||||
this.logger.succ(`Exported to: ${driveFile.id}`);
|
this.logger.succ(`Exported to: ${driveFile.id}`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -110,7 +110,7 @@ export class ExportFollowingProcessorService {
|
||||||
this.logger.succ(`Exported to: ${path}`);
|
this.logger.succ(`Exported to: ${path}`);
|
||||||
|
|
||||||
const fileName = 'following-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
const fileName = 'following-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
||||||
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true });
|
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true, ext: 'csv' });
|
||||||
|
|
||||||
this.logger.succ(`Exported to: ${driveFile.id}`);
|
this.logger.succ(`Exported to: ${driveFile.id}`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -110,7 +110,7 @@ export class ExportMutingProcessorService {
|
||||||
this.logger.succ(`Exported to: ${path}`);
|
this.logger.succ(`Exported to: ${path}`);
|
||||||
|
|
||||||
const fileName = 'mute-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
const fileName = 'mute-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
||||||
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true });
|
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true, ext: 'csv' });
|
||||||
|
|
||||||
this.logger.succ(`Exported to: ${driveFile.id}`);
|
this.logger.succ(`Exported to: ${driveFile.id}`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -117,7 +117,7 @@ export class ExportNotesProcessorService {
|
||||||
this.logger.succ(`Exported to: ${path}`);
|
this.logger.succ(`Exported to: ${path}`);
|
||||||
|
|
||||||
const fileName = 'notes-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.json';
|
const fileName = 'notes-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.json';
|
||||||
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true });
|
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true, ext: 'json' });
|
||||||
|
|
||||||
this.logger.succ(`Exported to: ${driveFile.id}`);
|
this.logger.succ(`Exported to: ${driveFile.id}`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -86,7 +86,7 @@ export class ExportUserListsProcessorService {
|
||||||
this.logger.succ(`Exported to: ${path}`);
|
this.logger.succ(`Exported to: ${path}`);
|
||||||
|
|
||||||
const fileName = 'user-lists-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
const fileName = 'user-lists-' + dateFormat(new Date(), 'yyyy-MM-dd-HH-mm-ss') + '.csv';
|
||||||
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true });
|
const driveFile = await this.driveService.addFile({ user, path, name: fileName, force: true, ext: 'csv' });
|
||||||
|
|
||||||
this.logger.succ(`Exported to: ${driveFile.id}`);
|
this.logger.succ(`Exported to: ${driveFile.id}`);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in a new issue