wip
This commit is contained in:
parent
1c7a194950
commit
6183262037
|
@ -16,7 +16,7 @@
|
||||||
<p>%i18n:@banner%</p>
|
<p>%i18n:@banner%</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="thumbnail" ref="thumbnail" :style="`background-color: ${ background }`">
|
<div class="thumbnail" ref="thumbnail" :style="`background-color: ${ background }`">
|
||||||
<img :src="file.url" alt="" @load="onThumbnailLoaded"/>
|
<img :src="file.thumbnailUrl" alt="" @load="onThumbnailLoaded"/>
|
||||||
</div>
|
</div>
|
||||||
<p class="name">
|
<p class="name">
|
||||||
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }}</span>
|
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }}</span>
|
||||||
|
|
|
@ -37,7 +37,7 @@ export default Vue.extend({
|
||||||
style(): any {
|
style(): any {
|
||||||
return {
|
return {
|
||||||
'background-color': this.image.properties.avgColor && this.image.properties.avgColor.length == 3 ? `rgb(${this.image.properties.avgColor.join(',')})` : 'transparent',
|
'background-color': this.image.properties.avgColor && this.image.properties.avgColor.length == 3 ? `rgb(${this.image.properties.avgColor.join(',')})` : 'transparent',
|
||||||
'background-image': this.raw ? `url(${this.image.url})` : `url(${this.image.url})`
|
'background-image': this.raw ? `url(${this.image.url})` : `url(${this.image.thumbnailUrl})`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -27,7 +27,7 @@ export default Vue.extend({
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
style(): any {
|
style(): any {
|
||||||
let url = `url(${this.image.url})`;
|
let url = `url(${this.image.thumbnailUrl})`;
|
||||||
|
|
||||||
if (this.$store.state.device.loadRemoteMedia || this.$store.state.device.lightmode) {
|
if (this.$store.state.device.loadRemoteMedia || this.$store.state.device.lightmode) {
|
||||||
url = null;
|
url = null;
|
||||||
|
|
|
@ -31,6 +31,7 @@ export type IMetadata = {
|
||||||
comment: string;
|
comment: string;
|
||||||
uri?: string;
|
uri?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
|
thumbnailUrl?: string;
|
||||||
src?: string;
|
src?: string;
|
||||||
deletedAt?: Date;
|
deletedAt?: Date;
|
||||||
withoutChunks?: boolean;
|
withoutChunks?: boolean;
|
||||||
|
@ -164,6 +165,7 @@ export const pack = (
|
||||||
_target = Object.assign(_target, _file.metadata);
|
_target = Object.assign(_target, _file.metadata);
|
||||||
|
|
||||||
_target.url = _file.metadata.url ? _file.metadata.url : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}`;
|
_target.url = _file.metadata.url ? _file.metadata.url : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}`;
|
||||||
|
_target.thumbnailUrl = _file.metadata.thumbnailUrl ? _file.metadata.thumbnailUrl : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}?thumbnail`;
|
||||||
_target.isRemote = _file.metadata.isRemote;
|
_target.isRemote = _file.metadata.isRemote;
|
||||||
|
|
||||||
if (_target.properties == null) _target.properties = {};
|
if (_target.properties == null) _target.properties = {};
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
import * as Koa from 'koa';
|
import * as Koa from 'koa';
|
||||||
import * as send from 'koa-send';
|
import * as send from 'koa-send';
|
||||||
import * as mongodb from 'mongodb';
|
import * as mongodb from 'mongodb';
|
||||||
|
@ -51,16 +49,10 @@ export default async function(ctx: Koa.Context) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if ('thumbnail' in ctx.query) {
|
if ('thumbnail' in ctx.query) {
|
||||||
// 画像以外
|
const thumb = await DriveFileThumbnail.findOne({
|
||||||
if (!file.contentType.startsWith('image/')) {
|
'metadata.originalId': fileId
|
||||||
const readable = fs.createReadStream(`${__dirname}/assets/thumbnail-not-available.png`);
|
});
|
||||||
ctx.set('Content-Type', 'image/png');
|
|
||||||
ctx.body = readable;
|
|
||||||
} else if (file.contentType == 'image/gif') {
|
|
||||||
// GIF
|
|
||||||
await sendRaw();
|
|
||||||
} else {
|
|
||||||
const thumb = await DriveFileThumbnail.findOne({ 'metadata.originalId': fileId });
|
|
||||||
if (thumb != null) {
|
if (thumb != null) {
|
||||||
ctx.set('Content-Type', 'image/jpeg');
|
ctx.set('Content-Type', 'image/jpeg');
|
||||||
const bucket = await getDriveFileThumbnailBucket();
|
const bucket = await getDriveFileThumbnailBucket();
|
||||||
|
@ -68,7 +60,6 @@ export default async function(ctx: Koa.Context) {
|
||||||
} else {
|
} else {
|
||||||
await sendRaw();
|
await sendRaw();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if ('download' in ctx.query) {
|
if ('download' in ctx.query) {
|
||||||
ctx.set('Content-Disposition', 'attachment');
|
ctx.set('Content-Disposition', 'attachment');
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as stream from 'stream';
|
|
||||||
|
|
||||||
import * as mongodb from 'mongodb';
|
import * as mongodb from 'mongodb';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
|
@ -26,9 +25,9 @@ async function save(path: string, name: string, type: string, hash: string, size
|
||||||
|
|
||||||
if (['image/jpeg', 'image/png', 'image/webp'].includes(type)) {
|
if (['image/jpeg', 'image/png', 'image/webp'].includes(type)) {
|
||||||
thumbnail = await sharp(path)
|
thumbnail = await sharp(path)
|
||||||
.resize(500)
|
.resize(300)
|
||||||
.jpeg({
|
.jpeg({
|
||||||
quality: 70,
|
quality: 50,
|
||||||
progressive: true
|
progressive: true
|
||||||
})
|
})
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
|
@ -104,8 +103,7 @@ async function save(path: string, name: string, type: string, hash: string, size
|
||||||
|
|
||||||
writeStream.once('finish', resolve);
|
writeStream.once('finish', resolve);
|
||||||
writeStream.on('error', reject);
|
writeStream.on('error', reject);
|
||||||
|
writeStream.end(thumbnail);
|
||||||
fs.createReadStream(path).pipe(writeStream);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,14 @@ import config from '../../config';
|
||||||
export default async function(file: IDriveFile, isExpired = false) {
|
export default async function(file: IDriveFile, isExpired = false) {
|
||||||
if (file.metadata.storage == 'minio') {
|
if (file.metadata.storage == 'minio') {
|
||||||
const minio = new Minio.Client(config.drive.config);
|
const minio = new Minio.Client(config.drive.config);
|
||||||
|
|
||||||
const obj = `${config.drive.prefix}/${file.metadata.storageProps.id}`;
|
const obj = `${config.drive.prefix}/${file.metadata.storageProps.id}`;
|
||||||
await minio.removeObject(config.drive.bucket, obj);
|
await minio.removeObject(config.drive.bucket, obj);
|
||||||
|
|
||||||
|
if (file.metadata.thumbnailUrl) {
|
||||||
|
const thumbnailObj = `${config.drive.prefix}/${file.metadata.storageProps.id}-thumbnail`;
|
||||||
|
await minio.removeObject(config.drive.bucket, thumbnailObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// チャンクをすべて削除
|
// チャンクをすべて削除
|
||||||
|
|
Loading…
Reference in a new issue