Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
d9cdc1f079 | |||
414c600356 | |||
e37c19fdcd | |||
d69b919961 | |||
1311db8060 | |||
ed9e7520f1 | |||
8fe6da0cad | |||
b8eac630ed | |||
a5b9d7eb3b | |||
06c453c3bc | |||
97b7567770 |
101
cli/clean-cached-remote-files.js
Normal file
101
cli/clean-cached-remote-files.js
Normal file
@ -0,0 +1,101 @@
|
||||
const chalk = require('chalk');
|
||||
const log = require('single-line-log').stdout;
|
||||
const sequential = require('promise-sequential');
|
||||
const { default: DriveFile, DriveFileChunk } = require('../built/models/drive-file');
|
||||
const { default: DriveFileThumbnail, DriveFileThumbnailChunk } = require('../built/models/drive-file-thumbnail');
|
||||
const { default: User } = require('../built/models/user');
|
||||
|
||||
const q = {
|
||||
'metadata._user.host': {
|
||||
$ne: null
|
||||
}
|
||||
};
|
||||
|
||||
async function main() {
|
||||
const promiseGens = [];
|
||||
|
||||
const count = await DriveFile.count(q);
|
||||
|
||||
let prev;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
promiseGens.push(() => {
|
||||
const promise = new Promise(async (res, rej) => {
|
||||
const file = await DriveFile.findOne(prev ? Object.assign({
|
||||
_id: { $lt: prev._id }
|
||||
}, q) : q, {
|
||||
sort: {
|
||||
_id: -1
|
||||
}
|
||||
});
|
||||
|
||||
prev = file;
|
||||
|
||||
function skip() {
|
||||
res([i, file, false]);
|
||||
}
|
||||
|
||||
if (file == null) return skip();
|
||||
|
||||
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
||||
|
||||
const attachingUsersCount = await User.count({
|
||||
$or: [{
|
||||
avatarId: file._id
|
||||
}, {
|
||||
bannerId: file._id
|
||||
}]
|
||||
}, { limit: 1 });
|
||||
if (attachingUsersCount !== 0) return skip();
|
||||
|
||||
Promise.all([
|
||||
// チャンクをすべて削除
|
||||
DriveFileChunk.remove({
|
||||
files_id: file._id
|
||||
}),
|
||||
|
||||
DriveFile.update({ _id: file._id }, {
|
||||
$set: {
|
||||
'metadata.deletedAt': new Date(),
|
||||
'metadata.isExpired': true
|
||||
}
|
||||
})
|
||||
]).then(async () => {
|
||||
res([i, file, true]);
|
||||
|
||||
//#region サムネイルもあれば削除
|
||||
const thumbnail = await DriveFileThumbnail.findOne({
|
||||
'metadata.originalId': file._id
|
||||
});
|
||||
|
||||
if (thumbnail) {
|
||||
DriveFileThumbnailChunk.remove({
|
||||
files_id: thumbnail._id
|
||||
});
|
||||
|
||||
DriveFileThumbnail.remove({ _id: thumbnail._id });
|
||||
}
|
||||
//#endregion
|
||||
});
|
||||
});
|
||||
|
||||
promise.then(([i, file, deleted]) => {
|
||||
if (deleted) {
|
||||
log(chalk`{gray ${i}} {red deleted: {bold ${file._id}} ${file.filename}}`);
|
||||
} else {
|
||||
log(chalk`{gray ${i}} {green skipped: {bold ${file._id}} ${file.filename}}`);
|
||||
}
|
||||
log.clear();
|
||||
console.log();
|
||||
});
|
||||
|
||||
return promise;
|
||||
});
|
||||
}
|
||||
|
||||
return await sequential(promiseGens);
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
console.log('ALL DONE');
|
||||
}).catch(console.error);
|
@ -6,10 +6,6 @@ const { default: Note } = require('../built/models/note');
|
||||
const { default: MessagingMessage } = require('../built/models/messaging-message');
|
||||
const { default: User } = require('../built/models/user');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
const skip = parseInt(args[0] || '0', 10);
|
||||
|
||||
async function main() {
|
||||
const promiseGens = [];
|
||||
|
||||
@ -17,13 +13,9 @@ async function main() {
|
||||
|
||||
let prev;
|
||||
|
||||
for (let i = skip; i < count; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
promiseGens.push(() => {
|
||||
const promise = new Promise(async (res, rej) => {
|
||||
function skip() {
|
||||
res([i, file, false]);
|
||||
}
|
||||
|
||||
const file = await DriveFile.findOne(prev ? {
|
||||
_id: { $lt: prev._id }
|
||||
} : {}, {
|
||||
@ -34,6 +26,10 @@ async function main() {
|
||||
|
||||
prev = file;
|
||||
|
||||
function skip() {
|
||||
res([i, file, false]);
|
||||
}
|
||||
|
||||
if (file == null) return skip();
|
||||
|
||||
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "misskey",
|
||||
"author": "syuilo <i@syuilo.com>",
|
||||
"version": "2.1.1",
|
||||
"clientVersion": "1.0.5188",
|
||||
"version": "2.2.0",
|
||||
"clientVersion": "1.0.5193",
|
||||
"codename": "nighthike",
|
||||
"main": "./built/index.js",
|
||||
"private": true,
|
||||
|
@ -26,7 +26,7 @@ export default Vue.extend({
|
||||
|
||||
<style lang="stylus" scoped>
|
||||
.mk-avatar
|
||||
display block
|
||||
display inline-block
|
||||
|
||||
> img
|
||||
display inline-block
|
||||
|
@ -28,7 +28,8 @@ export type IMetadata = {
|
||||
_user: any;
|
||||
folderId: mongo.ObjectID;
|
||||
comment: string;
|
||||
uri: string;
|
||||
uri?: string;
|
||||
url?: string;
|
||||
deletedAt?: Date;
|
||||
isExpired?: boolean;
|
||||
};
|
||||
|
@ -24,7 +24,7 @@ export async function createImage(actor: IRemoteUser, value): Promise<IDriveFile
|
||||
|
||||
log(`Creating the Image: ${image.url}`);
|
||||
|
||||
return await uploadFromUrl(image.url, actor);
|
||||
return await uploadFromUrl(image.url, actor, null, image.url);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,6 +6,8 @@ import * as mongodb from 'mongodb';
|
||||
import DriveFile, { getDriveFileBucket } from '../../models/drive-file';
|
||||
import DriveFileThumbnail, { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
|
||||
|
||||
const assets = `${__dirname}/../../server/file/assets/`;
|
||||
|
||||
const commonReadableHandlerGenerator = (ctx: Koa.Context) => (e: Error): void => {
|
||||
console.error(e);
|
||||
ctx.status = 500;
|
||||
@ -25,16 +27,16 @@ export default async function(ctx: Koa.Context) {
|
||||
|
||||
if (file == null) {
|
||||
ctx.status = 404;
|
||||
await send(ctx, `${__dirname}/assets/dummy.png`);
|
||||
await send(ctx, '/dummy.png', { root: assets });
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.metadata.deletedAt) {
|
||||
ctx.status = 410;
|
||||
if (file.metadata.isExpired) {
|
||||
await send(ctx, `${__dirname}/assets/cache-expired.png`);
|
||||
await send(ctx, '/cache-expired.png', { root: assets });
|
||||
} else {
|
||||
await send(ctx, `${__dirname}/assets/tombstone.png`);
|
||||
await send(ctx, '/tombstone.png', { root: assets });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -42,17 +42,21 @@ router.get('/assets/*', async ctx => {
|
||||
|
||||
// Apple touch icon
|
||||
router.get('/apple-touch-icon.png', async ctx => {
|
||||
await send(ctx, `${client}/assets/apple-touch-icon.png`);
|
||||
await send(ctx, '/assets/apple-touch-icon.png', {
|
||||
root: client
|
||||
});
|
||||
});
|
||||
|
||||
// ServiceWroker
|
||||
router.get(/^\/sw\.(.+?)\.js$/, async ctx => {
|
||||
await send(ctx, `${client}/assets/sw.${ctx.params[0]}.js`);
|
||||
});
|
||||
//router.get(/^\/sw\.(.+?)\.js$/, async ctx => {
|
||||
// await send(ctx, `${client}/assets/sw.${ctx.params[0]}.js`);
|
||||
//});
|
||||
|
||||
// Manifest
|
||||
router.get('/manifest.json', async ctx => {
|
||||
await send(ctx, `${client}/assets/manifest.json`);
|
||||
await send(ctx, '/assets/manifest.json', {
|
||||
root: client
|
||||
});
|
||||
});
|
||||
|
||||
//#endregion
|
||||
|
@ -62,6 +62,7 @@ const addFile = async (
|
||||
comment: string = null,
|
||||
folderId: mongodb.ObjectID = null,
|
||||
force: boolean = false,
|
||||
url: string = null,
|
||||
uri: string = null
|
||||
): Promise<IDriveFile> => {
|
||||
log(`registering ${name} (user: ${getAcct(user)}, path: ${path})`);
|
||||
@ -296,6 +297,10 @@ const addFile = async (
|
||||
properties: properties
|
||||
} as IMetadata;
|
||||
|
||||
if (url !== null) {
|
||||
metadata.url = url;
|
||||
}
|
||||
|
||||
if (uri !== null) {
|
||||
metadata.uri = uri;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ export default async (url, user, folderId = null, uri = null): Promise<IDriveFil
|
||||
let error;
|
||||
|
||||
try {
|
||||
driveFile = await create(user, path, name, null, folderId, false, uri);
|
||||
driveFile = await create(user, path, name, null, folderId, false, url, uri);
|
||||
log(`created: ${driveFile._id}`);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
|
Reference in New Issue
Block a user