URLに拡張子を付けた
This commit is contained in:
parent
1d3342e641
commit
1eece5ab3d
2 changed files with 23 additions and 15 deletions
|
@ -33,13 +33,21 @@ DriveFile.findOne({
|
||||||
}, {
|
}, {
|
||||||
'metadata.url': null
|
'metadata.url': null
|
||||||
}]
|
}]
|
||||||
}, { fields: { _id: true } }).then(xs => {
|
}, { fields: { _id: true, filename: true, contentType: true } }).then(xs => {
|
||||||
for (const x of xs) {
|
for (const x of xs) {
|
||||||
|
let [ext] = (x.filename.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
|
||||||
|
|
||||||
|
if (ext === '') {
|
||||||
|
if (x.contentType === 'image/jpeg') ext = '.jpg';
|
||||||
|
if (x.contentType === 'image/png') ext = '.png';
|
||||||
|
if (x.contentType === 'image/webp') ext = '.webp';
|
||||||
|
}
|
||||||
|
|
||||||
DriveFile.update({ _id: x._id }, {
|
DriveFile.update({ _id: x._id }, {
|
||||||
$set: {
|
$set: {
|
||||||
'metadata.url': `${config.driveUrl}/${uuid.v4()}`,
|
'metadata.url': `${config.driveUrl}/${uuid.v4()}${ext}`,
|
||||||
'metadata.webpublicUrl': `${config.driveUrl}/${uuid.v4()}?web`,
|
'metadata.webpublicUrl': `${config.driveUrl}/${uuid.v4()}.jpg`,
|
||||||
'metadata.thumbnailUrl': `${config.driveUrl}/${uuid.v4()}?thumbnail`,
|
'metadata.thumbnailUrl': `${config.driveUrl}/${uuid.v4()}.jpg`,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,16 +42,16 @@ async function save(path: string, name: string, type: string, hash: string, size
|
||||||
// thunbnail, webpublic を必要なら生成
|
// thunbnail, webpublic を必要なら生成
|
||||||
const alts = await generateAlts(path, type, !metadata.uri);
|
const alts = await generateAlts(path, type, !metadata.uri);
|
||||||
|
|
||||||
|
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
|
||||||
|
|
||||||
|
if (ext === '') {
|
||||||
|
if (type === 'image/jpeg') ext = '.jpg';
|
||||||
|
if (type === 'image/png') ext = '.png';
|
||||||
|
if (type === 'image/webp') ext = '.webp';
|
||||||
|
}
|
||||||
|
|
||||||
if (config.drive && config.drive.storage == 'minio') {
|
if (config.drive && config.drive.storage == 'minio') {
|
||||||
//#region ObjectStorage params
|
//#region ObjectStorage params
|
||||||
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
|
|
||||||
|
|
||||||
if (ext === '') {
|
|
||||||
if (type === 'image/jpeg') ext = '.jpg';
|
|
||||||
if (type === 'image/png') ext = '.png';
|
|
||||||
if (type === 'image/webp') ext = '.webp';
|
|
||||||
}
|
|
||||||
|
|
||||||
const baseUrl = config.drive.baseUrl
|
const baseUrl = config.drive.baseUrl
|
||||||
|| `${ config.drive.config.useSSL ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? `:${config.drive.config.port}` : '' }/${ config.drive.bucket }`;
|
|| `${ config.drive.config.useSSL ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? `:${config.drive.config.port}` : '' }/${ config.drive.bucket }`;
|
||||||
|
|
||||||
|
@ -118,9 +118,9 @@ async function save(path: string, name: string, type: string, hash: string, size
|
||||||
return file;
|
return file;
|
||||||
} else { // use MongoDB GridFS
|
} else { // use MongoDB GridFS
|
||||||
Object.assign(metadata, {
|
Object.assign(metadata, {
|
||||||
url: `${config.driveUrl}/${uuid.v4()}`,
|
url: `${config.driveUrl}/${uuid.v4()}${ext}`,
|
||||||
webpublicUrl: `${config.driveUrl}/${uuid.v4()}?web`,
|
webpublicUrl: `${config.driveUrl}/${uuid.v4()}.${alts.webpublic.ext}`,
|
||||||
thumbnailUrl: `${config.driveUrl}/${uuid.v4()}?thumbnail`,
|
thumbnailUrl: `${config.driveUrl}/${uuid.v4()}.${alts.thumbnail.ext}`,
|
||||||
} as IMetadata);
|
} as IMetadata);
|
||||||
|
|
||||||
// #region store original
|
// #region store original
|
||||||
|
|
Loading…
Reference in a new issue