mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 15:34:13 +00:00 
			
		
		
		
	add file extension to locally-stored media
This commit is contained in:
		
							parent
							
								
									d14f0b140b
								
							
						
					
					
						commit
						ad63f55a0f
					
				
					 1 changed files with 14 additions and 9 deletions
				
			
		| 
						 | 
					@ -37,6 +37,7 @@ import { InternalStorageService } from '@/core/InternalStorageService.js';
 | 
				
			||||||
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
 | 
					import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
 | 
				
			||||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
 | 
					import { UserEntityService } from '@/core/entities/UserEntityService.js';
 | 
				
			||||||
import { FileInfoService } from '@/core/FileInfoService.js';
 | 
					import { FileInfoService } from '@/core/FileInfoService.js';
 | 
				
			||||||
 | 
					import type { FileInfo } from '@/core/FileInfoService.js';
 | 
				
			||||||
import { bindThis } from '@/decorators.js';
 | 
					import { bindThis } from '@/decorators.js';
 | 
				
			||||||
import { RoleService } from '@/core/RoleService.js';
 | 
					import { RoleService } from '@/core/RoleService.js';
 | 
				
			||||||
import { correctFilename } from '@/misc/correct-filename.js';
 | 
					import { correctFilename } from '@/misc/correct-filename.js';
 | 
				
			||||||
| 
						 | 
					@ -139,14 +140,18 @@ export class DriveService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/***
 | 
						/***
 | 
				
			||||||
	 * Save file
 | 
						 * Save file
 | 
				
			||||||
 | 
						 * @param file
 | 
				
			||||||
	 * @param path Path for original
 | 
						 * @param path Path for original
 | 
				
			||||||
	 * @param name Name for original (should be extention corrected)
 | 
						 * @param name Name for original (should be extention corrected)
 | 
				
			||||||
	 * @param type Content-Type for original
 | 
						 * @param info File metadata
 | 
				
			||||||
	 * @param hash Hash for original
 | 
					 | 
				
			||||||
	 * @param size Size for original
 | 
					 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	@bindThis
 | 
						@bindThis
 | 
				
			||||||
	private async save(file: MiDriveFile, path: string, name: string, type: string, hash: string, size: number): Promise<MiDriveFile> {
 | 
						private async save(file: MiDriveFile, path: string, name: string, info: FileInfo): Promise<MiDriveFile> {
 | 
				
			||||||
 | 
							const type = info.type.mime;
 | 
				
			||||||
 | 
							const ext = info.type.ext;
 | 
				
			||||||
 | 
							const hash = info.md5;
 | 
				
			||||||
 | 
							const size = info.size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// thunbnail, webpublic を必要なら生成
 | 
							// thunbnail, webpublic を必要なら生成
 | 
				
			||||||
		const alts = await this.generateAlts(path, type, !file.uri);
 | 
							const alts = await this.generateAlts(path, type, !file.uri);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -223,9 +228,9 @@ export class DriveService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return await this.driveFilesRepository.insertOne(file);
 | 
								return await this.driveFilesRepository.insertOne(file);
 | 
				
			||||||
		} else { // use internal storage
 | 
							} else { // use internal storage
 | 
				
			||||||
			const accessKey = randomUUID();
 | 
								const accessKey = `${randomUUID()}.${ext}`;
 | 
				
			||||||
			const thumbnailAccessKey = 'thumbnail-' + randomUUID();
 | 
								const thumbnailAccessKey = `thumbnail-${randomUUID()}.${ext}`;
 | 
				
			||||||
			const webpublicAccessKey = 'webpublic-' + randomUUID();
 | 
								const webpublicAccessKey = `webpublic-${randomUUID()}.${ext}`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Ugly type is just to help TS figure out that 2nd / 3rd promises are optional.
 | 
								// Ugly type is just to help TS figure out that 2nd / 3rd promises are optional.
 | 
				
			||||||
			const promises: [Promise<string>, ...(Promise<string> | undefined)[]] = [
 | 
								const promises: [Promise<string>, ...(Promise<string> | undefined)[]] = [
 | 
				
			||||||
| 
						 | 
					@ -616,7 +621,7 @@ export class DriveService {
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			file = await (this.save(file, path, detectedName, info.type.mime, info.md5, info.size));
 | 
								file = await (this.save(file, path, detectedName, info));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		this.registerLogger.succ(`drive file has been created ${file.id}`);
 | 
							this.registerLogger.succ(`drive file has been created ${file.id}`);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue