This commit is contained in:
syuilo 2018-07-24 05:04:43 +09:00
parent 5458b10774
commit adc3c16ef3
5 changed files with 22 additions and 15 deletions

View File

@ -9,7 +9,7 @@ const q = {
'metadata._user.host': { 'metadata._user.host': {
$ne: null $ne: null
}, },
'metadata.isMetaOnly': false 'metadata.withoutChunks': false
}; };
async function main() { async function main() {
@ -57,7 +57,7 @@ async function main() {
DriveFile.update({ _id: file._id }, { DriveFile.update({ _id: file._id }, {
$set: { $set: {
'metadata.isMetaOnly': true 'metadata.withoutChunks': true
} }
}) })
]).then(async () => { ]).then(async () => {

View File

@ -31,8 +31,9 @@ export type IMetadata = {
comment: string; comment: string;
uri?: string; uri?: string;
url?: string; url?: string;
src?: string;
deletedAt?: Date; deletedAt?: Date;
isMetaOnly?: boolean; withoutChunks?: boolean;
isSensitive?: boolean; isSensitive?: boolean;
}; };
@ -155,9 +156,9 @@ 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.src = _file.metadata.url; _target.src = _file.metadata.url;
_target.url = _file.metadata.isMetaOnly ? _file.metadata.url : `${config.drive_url}/${_target.id}/${encodeURIComponent(_target.name)}`; _target.isRemote = _file.metadata.withoutChunks;
_target.isRemote = _file.metadata.isMetaOnly;
if (_target.properties == null) _target.properties = {}; if (_target.properties == null) _target.properties = {};

View File

@ -152,8 +152,8 @@ export async function createPerson(value: any, resolver?: Resolver): Promise<IUs
const avatarId = avatar ? avatar._id : null; const avatarId = avatar ? avatar._id : null;
const bannerId = banner ? banner._id : null; const bannerId = banner ? banner._id : null;
const avatarUrl = avatar && avatar.metadata.isMetaOnly ? avatar.metadata.url : null; const avatarUrl = avatar && avatar.metadata.url ? avatar.metadata.url : null;
const bannerUrl = banner && banner.metadata.isMetaOnly ? banner.metadata.url : null; const bannerUrl = banner && banner.metadata.url ? banner.metadata.url : null;
await User.update({ _id: user._id }, { await User.update({ _id: user._id }, {
$set: { $set: {
@ -243,8 +243,8 @@ export async function updatePerson(value: string | IObject, resolver?: Resolver)
sharedInbox: person.sharedInbox, sharedInbox: person.sharedInbox,
avatarId: avatar ? avatar._id : null, avatarId: avatar ? avatar._id : null,
bannerId: banner ? banner._id : null, bannerId: banner ? banner._id : null,
avatarUrl: avatar && avatar.metadata.isMetaOnly ? avatar.metadata.url : null, avatarUrl: avatar && avatar.metadata.url ? avatar.metadata.url : null,
bannerUrl: banner && banner.metadata.isMetaOnly ? banner.metadata.url : null, bannerUrl: banner && banner.metadata.url ? banner.metadata.url : null,
description: htmlToMFM(person.summary), description: htmlToMFM(person.summary),
followersCount, followersCount,
followingCount, followingCount,

View File

@ -37,7 +37,7 @@ export default async function(ctx: Koa.Context) {
return; return;
} }
if (file.metadata.isMetaOnly) { if (file.metadata.withoutChunks) {
ctx.status = 204; ctx.status = 204;
return; return;
} }

View File

@ -35,6 +35,8 @@ async function save(readable: stream.Readable, name: string, type: string, hash:
await minio.putObject(config.drive.bucket, obj, readable); await minio.putObject(config.drive.bucket, obj, readable);
Object.assign(metadata, { Object.assign(metadata, {
storage: 'object-storage',
withoutChunks: true,
obj: id, obj: id,
url: `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }/${ obj }` url: `${ config.drive.config.secure ? 'https' : 'http' }://${ config.drive.config.endPoint }${ config.drive.config.port ? ':' + config.drive.config.port : '' }/${ config.drive.bucket }/${ obj }`
}); });
@ -97,7 +99,7 @@ export default async function(
comment: string = null, comment: string = null,
folderId: mongodb.ObjectID = null, folderId: mongodb.ObjectID = null,
force: boolean = false, force: boolean = false,
metaOnly: boolean = false, isLink: boolean = false,
url: string = null, url: string = null,
uri: string = null, uri: string = null,
sensitive = false sensitive = false
@ -165,7 +167,7 @@ export default async function(
} }
//#region Check drive usage //#region Check drive usage
if (!metaOnly) { if (!isLink) {
const usage = await DriveFile const usage = await DriveFile
.aggregate([{ .aggregate([{
$match: { $match: {
@ -277,19 +279,23 @@ export default async function(
folderId: folder !== null ? folder._id : null, folderId: folder !== null ? folder._id : null,
comment: comment, comment: comment,
properties: properties, properties: properties,
isMetaOnly: metaOnly, withoutChunks: isLink,
isSensitive: sensitive isSensitive: sensitive
} as IMetadata; } as IMetadata;
if (url !== null) { if (url !== null) {
metadata.url = url; metadata.src = url;
if (isLink) {
metadata.url = url;
}
} }
if (uri !== null) { if (uri !== null) {
metadata.uri = uri; metadata.uri = uri;
} }
const driveFile = metaOnly const driveFile = isLink
? await DriveFile.insert({ ? await DriveFile.insert({
length: 0, length: 0,
uploadDate: new Date(), uploadDate: new Date(),