Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
1311db8060 | |||
ed9e7520f1 | |||
8fe6da0cad | |||
b8eac630ed | |||
a5b9d7eb3b | |||
06c453c3bc | |||
97b7567770 | |||
34345ea8a7 | |||
fc166b7bee | |||
cf3112c7c0 | |||
e7dd74a443 |
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: MessagingMessage } = require('../built/models/messaging-message');
|
||||||
const { default: User } = require('../built/models/user');
|
const { default: User } = require('../built/models/user');
|
||||||
|
|
||||||
const args = process.argv.slice(2);
|
|
||||||
|
|
||||||
const skip = parseInt(args[0] || '0', 10);
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const promiseGens = [];
|
const promiseGens = [];
|
||||||
|
|
||||||
@ -17,13 +13,9 @@ async function main() {
|
|||||||
|
|
||||||
let prev;
|
let prev;
|
||||||
|
|
||||||
for (let i = skip; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
promiseGens.push(() => {
|
promiseGens.push(() => {
|
||||||
const promise = new Promise(async (res, rej) => {
|
const promise = new Promise(async (res, rej) => {
|
||||||
function skip() {
|
|
||||||
res([i, file, false]);
|
|
||||||
}
|
|
||||||
|
|
||||||
const file = await DriveFile.findOne(prev ? {
|
const file = await DriveFile.findOne(prev ? {
|
||||||
_id: { $lt: prev._id }
|
_id: { $lt: prev._id }
|
||||||
} : {}, {
|
} : {}, {
|
||||||
@ -34,6 +26,10 @@ async function main() {
|
|||||||
|
|
||||||
prev = file;
|
prev = file;
|
||||||
|
|
||||||
|
function skip() {
|
||||||
|
res([i, file, false]);
|
||||||
|
}
|
||||||
|
|
||||||
if (file == null) return skip();
|
if (file == null) return skip();
|
||||||
|
|
||||||
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
log(chalk`{gray ${i}} scanning {bold ${file._id}} ${file.filename} ...`);
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"author": "syuilo <i@syuilo.com>",
|
"author": "syuilo <i@syuilo.com>",
|
||||||
"version": "2.0.0",
|
"version": "2.1.3",
|
||||||
"clientVersion": "1.0.5184",
|
"clientVersion": "1.0.5193",
|
||||||
"codename": "nighthike",
|
"codename": "nighthike",
|
||||||
"main": "./built/index.js",
|
"main": "./built/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
@ -26,7 +26,7 @@ export default Vue.extend({
|
|||||||
|
|
||||||
<style lang="stylus" scoped>
|
<style lang="stylus" scoped>
|
||||||
.mk-avatar
|
.mk-avatar
|
||||||
display block
|
display inline-block
|
||||||
|
|
||||||
> img
|
> img
|
||||||
display inline-block
|
display inline-block
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
<section v-if="myGames.length > 0">
|
<section v-if="myGames.length > 0">
|
||||||
<h2>自分の対局</h2>
|
<h2>自分の対局</h2>
|
||||||
<a class="game" v-for="g in myGames" tabindex="-1" @click.prevent="go(g)" :href="`/othello/${g.id}`">
|
<a class="game" v-for="g in myGames" tabindex="-1" @click.prevent="go(g)" :href="`/othello/${g.id}`">
|
||||||
<mk-avatar class="avatar" :user="g.user1.avatarUrl"/>
|
<mk-avatar class="avatar" :user="g.user1"/>
|
||||||
<mk-avatar class="avatar" :user="g.user2.avatarUrl"/>
|
<mk-avatar class="avatar" :user="g.user2"/>
|
||||||
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
||||||
<span class="state">{{ g.isEnded ? '終了' : '進行中' }}</span>
|
<span class="state">{{ g.isEnded ? '終了' : '進行中' }}</span>
|
||||||
</a>
|
</a>
|
||||||
@ -49,8 +49,8 @@
|
|||||||
<section v-if="games.length > 0">
|
<section v-if="games.length > 0">
|
||||||
<h2>みんなの対局</h2>
|
<h2>みんなの対局</h2>
|
||||||
<a class="game" v-for="g in games" tabindex="-1" @click.prevent="go(g)" :href="`/othello/${g.id}`">
|
<a class="game" v-for="g in games" tabindex="-1" @click.prevent="go(g)" :href="`/othello/${g.id}`">
|
||||||
<mk-avatar class="avatar" :user="g.user1.avatarUrl"/>
|
<mk-avatar class="avatar" :user="g.user1"/>
|
||||||
<mk-avatar class="avatar" :user="g.user2.avatarUrl"/>
|
<mk-avatar class="avatar" :user="g.user2"/>
|
||||||
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
<span><b>{{ g.user1.name }}</b> vs <b>{{ g.user2.name }}</b></span>
|
||||||
<span class="state">{{ g.isEnded ? '終了' : '進行中' }}</span>
|
<span class="state">{{ g.isEnded ? '終了' : '進行中' }}</span>
|
||||||
</a>
|
</a>
|
||||||
@ -272,6 +272,8 @@ export default Vue.extend({
|
|||||||
background #eee
|
background #eee
|
||||||
|
|
||||||
> .avatar
|
> .avatar
|
||||||
|
width 32px
|
||||||
|
height 32px
|
||||||
border-radius 100%
|
border-radius 100%
|
||||||
|
|
||||||
> span
|
> span
|
||||||
@ -301,6 +303,8 @@ export default Vue.extend({
|
|||||||
background #eee
|
background #eee
|
||||||
|
|
||||||
> .avatar
|
> .avatar
|
||||||
|
width 32px
|
||||||
|
height 32px
|
||||||
border-radius 100%
|
border-radius 100%
|
||||||
|
|
||||||
> span
|
> span
|
||||||
|
@ -30,6 +30,7 @@ export type IMetadata = {
|
|||||||
comment: string;
|
comment: string;
|
||||||
uri: string;
|
uri: string;
|
||||||
deletedAt?: Date;
|
deletedAt?: Date;
|
||||||
|
isExpired?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IDriveFile = {
|
export type IDriveFile = {
|
||||||
|
BIN
src/server/file/assets/cache-expired.png
Normal file
BIN
src/server/file/assets/cache-expired.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
@ -6,6 +6,8 @@ import * as mongodb from 'mongodb';
|
|||||||
import DriveFile, { getDriveFileBucket } from '../../models/drive-file';
|
import DriveFile, { getDriveFileBucket } from '../../models/drive-file';
|
||||||
import DriveFileThumbnail, { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
|
import DriveFileThumbnail, { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
|
||||||
|
|
||||||
|
const assets = `${__dirname}/../../server/file/assets/`;
|
||||||
|
|
||||||
const commonReadableHandlerGenerator = (ctx: Koa.Context) => (e: Error): void => {
|
const commonReadableHandlerGenerator = (ctx: Koa.Context) => (e: Error): void => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
ctx.status = 500;
|
ctx.status = 500;
|
||||||
@ -25,13 +27,17 @@ export default async function(ctx: Koa.Context) {
|
|||||||
|
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
ctx.status = 404;
|
ctx.status = 404;
|
||||||
await send(ctx, `${__dirname}/assets/dummy.png`);
|
await send(ctx, `${__dirname}/assets/dummy.png`, { root: assets });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.metadata.deletedAt) {
|
if (file.metadata.deletedAt) {
|
||||||
ctx.status = 410;
|
ctx.status = 410;
|
||||||
await send(ctx, `${__dirname}/assets/tombstone.png`);
|
if (file.metadata.isExpired) {
|
||||||
|
await send(ctx, `${__dirname}/assets/cache-expired.png`, { root: assets });
|
||||||
|
} else {
|
||||||
|
await send(ctx, `${__dirname}/assets/tombstone.png`, { root: assets });
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,17 +42,21 @@ router.get('/assets/*', async ctx => {
|
|||||||
|
|
||||||
// Apple touch icon
|
// Apple touch icon
|
||||||
router.get('/apple-touch-icon.png', async ctx => {
|
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
|
// ServiceWroker
|
||||||
router.get(/^\/sw\.(.+?)\.js$/, async ctx => {
|
//router.get(/^\/sw\.(.+?)\.js$/, async ctx => {
|
||||||
await send(ctx, `${client}/assets/sw.${ctx.params[0]}.js`);
|
// await send(ctx, `${client}/assets/sw.${ctx.params[0]}.js`);
|
||||||
});
|
//});
|
||||||
|
|
||||||
// Manifest
|
// Manifest
|
||||||
router.get('/manifest.json', async ctx => {
|
router.get('/manifest.json', async ctx => {
|
||||||
await send(ctx, `${client}/assets/manifest.json`);
|
await send(ctx, '/assets/manifest.json', {
|
||||||
|
root: client
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
@ -201,7 +201,10 @@ const addFile = async (
|
|||||||
// Calculate drive usage
|
// Calculate drive usage
|
||||||
const usage = await DriveFile
|
const usage = await DriveFile
|
||||||
.aggregate([{
|
.aggregate([{
|
||||||
$match: { 'metadata.userId': user._id }
|
$match: {
|
||||||
|
'metadata.userId': user._id,
|
||||||
|
'metadata.deletedAt': { $exists: false }
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
$project: {
|
$project: {
|
||||||
length: true
|
length: true
|
||||||
@ -245,7 +248,8 @@ const addFile = async (
|
|||||||
|
|
||||||
DriveFile.update({ _id: oldFile._id }, {
|
DriveFile.update({ _id: oldFile._id }, {
|
||||||
$set: {
|
$set: {
|
||||||
'metadata.deletedAt': new Date()
|
'metadata.deletedAt': new Date(),
|
||||||
|
'metadata.isExpired': true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user