Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
24ef98eb01 | |||
7ed50b90bd | |||
b6fd5d7282 | |||
33243e7176 | |||
e8439679a5 | |||
06124dbbd5 | |||
857940f402 | |||
bcb04924ff | |||
0863e5d379 | |||
55dcd25df1 | |||
f3155ea180 | |||
2c5162671c | |||
fc8aeb5a66 | |||
995cf503eb | |||
0e49c11a4c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,3 +17,4 @@ api-docs.json
|
|||||||
/mongo
|
/mongo
|
||||||
/elasticsearch
|
/elasticsearch
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
yarn.lock
|
||||||
|
12
Dockerfile
12
Dockerfile
@ -8,18 +8,20 @@ WORKDIR /misskey
|
|||||||
|
|
||||||
FROM base AS builder
|
FROM base AS builder
|
||||||
|
|
||||||
|
RUN unlink /usr/bin/free
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
gcc \
|
|
||||||
g++ \
|
|
||||||
libc-dev \
|
|
||||||
python \
|
|
||||||
autoconf \
|
autoconf \
|
||||||
automake \
|
automake \
|
||||||
file \
|
file \
|
||||||
|
g++ \
|
||||||
|
gcc \
|
||||||
|
libc-dev \
|
||||||
|
libtool \
|
||||||
make \
|
make \
|
||||||
nasm \
|
nasm \
|
||||||
pkgconfig \
|
pkgconfig \
|
||||||
libtool \
|
procps \
|
||||||
|
python \
|
||||||
zlib-dev
|
zlib-dev
|
||||||
RUN npm i -g node-gyp
|
RUN npm i -g node-gyp
|
||||||
|
|
||||||
|
@ -1092,17 +1092,17 @@ admin/views/instance.vue:
|
|||||||
recaptcha-site-key: "reCAPTCHA site key"
|
recaptcha-site-key: "reCAPTCHA site key"
|
||||||
recaptcha-secret-key: "reCAPTCHA secret key"
|
recaptcha-secret-key: "reCAPTCHA secret key"
|
||||||
twitter-integration-config: "Twitter連携の設定"
|
twitter-integration-config: "Twitter連携の設定"
|
||||||
twitter-integration-info: "コールバックURLは /api/tw/cb に設定します。"
|
twitter-integration-info: "コールバックURLは {url} に設定します。"
|
||||||
enable-twitter-integration: "Twitter連携を有効にする"
|
enable-twitter-integration: "Twitter連携を有効にする"
|
||||||
twitter-integration-consumer-key: "Consumer key"
|
twitter-integration-consumer-key: "Consumer key"
|
||||||
twitter-integration-consumer-secret: "Consumer secret"
|
twitter-integration-consumer-secret: "Consumer secret"
|
||||||
github-integration-config: "GitHub連携の設定"
|
github-integration-config: "GitHub連携の設定"
|
||||||
github-integration-info: "コールバックURLは /api/gh/cb に設定します。"
|
github-integration-info: "コールバックURLは {url} に設定します。"
|
||||||
enable-github-integration: "GitHub連携を有効にする"
|
enable-github-integration: "GitHub連携を有効にする"
|
||||||
github-integration-client-id: "Client ID"
|
github-integration-client-id: "Client ID"
|
||||||
github-integration-client-secret: "Client Secret"
|
github-integration-client-secret: "Client Secret"
|
||||||
discord-integration-config: "Discord連携の設定"
|
discord-integration-config: "Discord連携の設定"
|
||||||
discord-integration-info: "コールバックURLは /api/dc/cb に設定します。"
|
discord-integration-info: "コールバックURLは {url} に設定します。"
|
||||||
enable-discord-integration: "Discord連携を有効にする"
|
enable-discord-integration: "Discord連携を有効にする"
|
||||||
discord-integration-client-id: "Client ID"
|
discord-integration-client-id: "Client ID"
|
||||||
discord-integration-client-secret: "Client Secret"
|
discord-integration-client-secret: "Client Secret"
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"author": "syuilo <i@syuilo.com>",
|
"author": "syuilo <i@syuilo.com>",
|
||||||
"version": "10.57.3",
|
"version": "10.58.1",
|
||||||
"clientVersion": "2.0.12095",
|
"clientVersion": "2.0.12110",
|
||||||
"codename": "nighthike",
|
"codename": "nighthike",
|
||||||
"main": "./built/index.js",
|
"main": "./built/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
<div slot="title"><fa :icon="['fab', 'twitter']"/> {{ $t('twitter-integration-config') }}</div>
|
<div slot="title"><fa :icon="['fab', 'twitter']"/> {{ $t('twitter-integration-config') }}</div>
|
||||||
<section>
|
<section>
|
||||||
<ui-switch v-model="enableTwitterIntegration">{{ $t('enable-twitter-integration') }}</ui-switch>
|
<ui-switch v-model="enableTwitterIntegration">{{ $t('enable-twitter-integration') }}</ui-switch>
|
||||||
<ui-info>{{ $t('twitter-integration-info') }}</ui-info>
|
<ui-info>{{ $t('twitter-integration-info', { url: `${url}/api/tw/cb` }) }}</ui-info>
|
||||||
<ui-input v-model="twitterConsumerKey" :disabled="!enableTwitterIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('twitter-integration-consumer-key') }}</ui-input>
|
<ui-input v-model="twitterConsumerKey" :disabled="!enableTwitterIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('twitter-integration-consumer-key') }}</ui-input>
|
||||||
<ui-input v-model="twitterConsumerSecret" :disabled="!enableTwitterIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('twitter-integration-consumer-secret') }}</ui-input>
|
<ui-input v-model="twitterConsumerSecret" :disabled="!enableTwitterIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('twitter-integration-consumer-secret') }}</ui-input>
|
||||||
<ui-button @click="updateMeta">{{ $t('save') }}</ui-button>
|
<ui-button @click="updateMeta">{{ $t('save') }}</ui-button>
|
||||||
@ -80,7 +80,7 @@
|
|||||||
<div slot="title"><fa :icon="['fab', 'github']"/> {{ $t('github-integration-config') }}</div>
|
<div slot="title"><fa :icon="['fab', 'github']"/> {{ $t('github-integration-config') }}</div>
|
||||||
<section>
|
<section>
|
||||||
<ui-switch v-model="enableGithubIntegration">{{ $t('enable-github-integration') }}</ui-switch>
|
<ui-switch v-model="enableGithubIntegration">{{ $t('enable-github-integration') }}</ui-switch>
|
||||||
<ui-info>{{ $t('github-integration-info') }}</ui-info>
|
<ui-info>{{ $t('github-integration-info', { url: `${url}/api/gh/cb` }) }}</ui-info>
|
||||||
<ui-input v-model="githubClientId" :disabled="!enableGithubIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('github-integration-client-id') }}</ui-input>
|
<ui-input v-model="githubClientId" :disabled="!enableGithubIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('github-integration-client-id') }}</ui-input>
|
||||||
<ui-input v-model="githubClientSecret" :disabled="!enableGithubIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('github-integration-client-secret') }}</ui-input>
|
<ui-input v-model="githubClientSecret" :disabled="!enableGithubIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('github-integration-client-secret') }}</ui-input>
|
||||||
<ui-button @click="updateMeta">{{ $t('save') }}</ui-button>
|
<ui-button @click="updateMeta">{{ $t('save') }}</ui-button>
|
||||||
@ -91,7 +91,7 @@
|
|||||||
<div slot="title"><fa :icon="['fab', 'discord']"/> {{ $t('discord-integration-config') }}</div>
|
<div slot="title"><fa :icon="['fab', 'discord']"/> {{ $t('discord-integration-config') }}</div>
|
||||||
<section>
|
<section>
|
||||||
<ui-switch v-model="enableDiscordIntegration">{{ $t('enable-discord-integration') }}</ui-switch>
|
<ui-switch v-model="enableDiscordIntegration">{{ $t('enable-discord-integration') }}</ui-switch>
|
||||||
<ui-info>{{ $t('discord-integration-info') }}</ui-info>
|
<ui-info>{{ $t('discord-integration-info', { url: `${url}/api/dc/cb` }) }}</ui-info>
|
||||||
<ui-input v-model="discordClientId" :disabled="!enableDiscordIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('discord-integration-client-id') }}</ui-input>
|
<ui-input v-model="discordClientId" :disabled="!enableDiscordIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('discord-integration-client-id') }}</ui-input>
|
||||||
<ui-input v-model="discordClientSecret" :disabled="!enableDiscordIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('discord-integration-client-secret') }}</ui-input>
|
<ui-input v-model="discordClientSecret" :disabled="!enableDiscordIntegration"><i slot="icon"><fa icon="key"/></i>{{ $t('discord-integration-client-secret') }}</ui-input>
|
||||||
<ui-button @click="updateMeta">{{ $t('save') }}</ui-button>
|
<ui-button @click="updateMeta">{{ $t('save') }}</ui-button>
|
||||||
@ -103,7 +103,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import i18n from '../../i18n';
|
import i18n from '../../i18n';
|
||||||
import { host } from '../../config';
|
import { url, host } from '../../config';
|
||||||
import { toUnicode } from 'punycode';
|
import { toUnicode } from 'punycode';
|
||||||
import { faHeadset, faShieldAlt, faGhost, faUserPlus } from '@fortawesome/free-solid-svg-icons';
|
import { faHeadset, faShieldAlt, faGhost, faUserPlus } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
@ -112,6 +112,7 @@ export default Vue.extend({
|
|||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
url,
|
||||||
host: toUnicode(host),
|
host: toUnicode(host),
|
||||||
maintainerName: null,
|
maintainerName: null,
|
||||||
maintainerEmail: null,
|
maintainerEmail: null,
|
||||||
|
@ -80,7 +80,7 @@ export default (opts: Opts = {}) => ({
|
|||||||
const ast = parse(this.appearNote.text);
|
const ast = parse(this.appearNote.text);
|
||||||
// TODO: 再帰的にURL要素がないか調べる
|
// TODO: 再帰的にURL要素がないか調べる
|
||||||
return unique(ast
|
return unique(ast
|
||||||
.filter(t => ((t.name == 'url' || t.name == 'link') && t.props.url && !t.silent))
|
.filter(t => ((t.name == 'url' || t.name == 'link') && t.props.url && !t.props.silent))
|
||||||
.map(t => t.props.url));
|
.map(t => t.props.url));
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -111,6 +111,14 @@ export default Vue.component('misskey-flavored-markdown', {
|
|||||||
}, genEl(token.children));
|
}, genEl(token.children));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'center': {
|
||||||
|
return [createElement('div', {
|
||||||
|
attrs: {
|
||||||
|
style: 'text-align:center;'
|
||||||
|
}
|
||||||
|
}, genEl(token.children))];
|
||||||
|
}
|
||||||
|
|
||||||
case 'motion': {
|
case 'motion': {
|
||||||
motionCount++;
|
motionCount++;
|
||||||
const isLong = getTextCount(token.children) > 10 || getChildrenCount(token.children) > 5;
|
const isLong = getTextCount(token.children) > 10 || getChildrenCount(token.children) > 5;
|
||||||
|
@ -29,7 +29,7 @@ export default Vue.extend({
|
|||||||
|
|
||||||
>>> .quote
|
>>> .quote
|
||||||
margin 8px
|
margin 8px
|
||||||
padding 6px 12px
|
padding 6px 0 6px 12px
|
||||||
color var(--mfmQuote)
|
color var(--mfmQuote)
|
||||||
border-left solid 3px var(--mfmQuoteLine)
|
border-left solid 3px var(--mfmQuoteLine)
|
||||||
|
|
||||||
|
@ -45,6 +45,12 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
|
|||||||
return pre;
|
return pre;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
center(token) {
|
||||||
|
const el = doc.createElement('div');
|
||||||
|
dive(token.children).forEach(child => el.appendChild(child));
|
||||||
|
return el;
|
||||||
|
},
|
||||||
|
|
||||||
emoji(token) {
|
emoji(token) {
|
||||||
return doc.createTextNode(token.props.emoji ? token.props.emoji : `:${token.props.name}:`);
|
return doc.createTextNode(token.props.emoji ? token.props.emoji : `:${token.props.name}:`);
|
||||||
},
|
},
|
||||||
|
@ -41,7 +41,7 @@ export default (source: string): Node[] => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isBlockNode(node: Node): boolean {
|
function isBlockNode(node: Node): boolean {
|
||||||
return ['blockCode', 'quote', 'title'].includes(node.name);
|
return ['blockCode', 'center', 'quote', 'title'].includes(node.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,26 @@ function makeNodeWithChildren(name: string, children: Node[], props?: any): Node
|
|||||||
return _makeNode(name, children, props);
|
return _makeNode(name, children, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTrailingPosition(x: string): number {
|
||||||
|
let pendingBracket = 0;
|
||||||
|
const end = x.split('').findIndex(char => {
|
||||||
|
if (char == ')') {
|
||||||
|
if (pendingBracket > 0) {
|
||||||
|
pendingBracket--;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (char == '(') {
|
||||||
|
pendingBracket++;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return end > 0 ? end : x.length;
|
||||||
|
}
|
||||||
|
|
||||||
const newline = P((input, i) => {
|
const newline = P((input, i) => {
|
||||||
if (i == 0 || input[i] == '\n' || input[i - 1] == '\n') {
|
if (i == 0 || input[i] == '\n' || input[i - 1] == '\n') {
|
||||||
return P.makeSuccess(i, null);
|
return P.makeSuccess(i, null);
|
||||||
@ -53,6 +73,7 @@ const mfm = P.createLanguage({
|
|||||||
r.math,
|
r.math,
|
||||||
r.search,
|
r.search,
|
||||||
r.title,
|
r.title,
|
||||||
|
r.center,
|
||||||
r.text
|
r.text
|
||||||
).atLeast(1),
|
).atLeast(1),
|
||||||
|
|
||||||
@ -65,6 +86,7 @@ const mfm = P.createLanguage({
|
|||||||
r.mention,
|
r.mention,
|
||||||
r.hashtag,
|
r.hashtag,
|
||||||
r.emoji,
|
r.emoji,
|
||||||
|
r.math,
|
||||||
r.text
|
r.text
|
||||||
).atLeast(1).tryParse(x))),
|
).atLeast(1).tryParse(x))),
|
||||||
//#endregion
|
//#endregion
|
||||||
@ -87,11 +109,30 @@ const mfm = P.createLanguage({
|
|||||||
.map(x => makeNodeWithChildren('bold', P.alt(
|
.map(x => makeNodeWithChildren('bold', P.alt(
|
||||||
r.mention,
|
r.mention,
|
||||||
r.hashtag,
|
r.hashtag,
|
||||||
|
r.url,
|
||||||
|
r.link,
|
||||||
r.emoji,
|
r.emoji,
|
||||||
r.text
|
r.text
|
||||||
).atLeast(1).tryParse(x))),
|
).atLeast(1).tryParse(x))),
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
//#region Center
|
||||||
|
center: r =>
|
||||||
|
P.regexp(/<center>([\s\S]+?)<\/center>/, 1)
|
||||||
|
.map(x => makeNodeWithChildren('center', P.alt(
|
||||||
|
r.big,
|
||||||
|
r.bold,
|
||||||
|
r.motion,
|
||||||
|
r.mention,
|
||||||
|
r.hashtag,
|
||||||
|
r.emoji,
|
||||||
|
r.math,
|
||||||
|
r.url,
|
||||||
|
r.link,
|
||||||
|
r.text
|
||||||
|
).atLeast(1).tryParse(x))),
|
||||||
|
//#endregion
|
||||||
|
|
||||||
//#region Emoji
|
//#region Emoji
|
||||||
emoji: r =>
|
emoji: r =>
|
||||||
P.alt(
|
P.alt(
|
||||||
@ -113,23 +154,7 @@ const mfm = P.createLanguage({
|
|||||||
const match = text.match(/^#([^\s\.,!\?#]+)/i);
|
const match = text.match(/^#([^\s\.,!\?#]+)/i);
|
||||||
if (!match) return P.makeFailure(i, 'not a hashtag');
|
if (!match) return P.makeFailure(i, 'not a hashtag');
|
||||||
let hashtag = match[1];
|
let hashtag = match[1];
|
||||||
let pendingBracket = 0;
|
hashtag = hashtag.substr(0, getTrailingPosition(hashtag));
|
||||||
const end = hashtag.split('').findIndex(char => {
|
|
||||||
if (char == ')') {
|
|
||||||
if (pendingBracket > 0) {
|
|
||||||
pendingBracket--;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if (char == '(') {
|
|
||||||
pendingBracket++;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (end > 0) hashtag = hashtag.substr(0, end);
|
|
||||||
if (hashtag.match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag');
|
if (hashtag.match(/^[0-9]+$/)) return P.makeFailure(i, 'not a hashtag');
|
||||||
if (!['\n', ' ', '(', null, undefined].includes(input[i - 1])) return P.makeFailure(i, 'require space before "#"');
|
if (!['\n', ' ', '(', null, undefined].includes(input[i - 1])) return P.makeFailure(i, 'require space before "#"');
|
||||||
return P.makeSuccess(i + ('#' + hashtag).length, makeNode('hashtag', { hashtag: hashtag }));
|
return P.makeSuccess(i + ('#' + hashtag).length, makeNode('hashtag', { hashtag: hashtag }));
|
||||||
@ -199,6 +224,9 @@ const mfm = P.createLanguage({
|
|||||||
r.mention,
|
r.mention,
|
||||||
r.hashtag,
|
r.hashtag,
|
||||||
r.emoji,
|
r.emoji,
|
||||||
|
r.url,
|
||||||
|
r.link,
|
||||||
|
r.math,
|
||||||
r.text
|
r.text
|
||||||
).atLeast(1).tryParse(x))),
|
).atLeast(1).tryParse(x))),
|
||||||
//#endregion
|
//#endregion
|
||||||
@ -264,23 +292,7 @@ const mfm = P.createLanguage({
|
|||||||
const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.,=\+\-]+/);
|
const match = text.match(/^https?:\/\/[\w\/:%#@\$&\?!\(\)\[\]~\.,=\+\-]+/);
|
||||||
if (!match) return P.makeFailure(i, 'not a url');
|
if (!match) return P.makeFailure(i, 'not a url');
|
||||||
let url = match[0];
|
let url = match[0];
|
||||||
let pendingBracket = 0;
|
url = url.substr(0, getTrailingPosition(url));
|
||||||
const end = url.split('').findIndex(char => {
|
|
||||||
if (char == ')') {
|
|
||||||
if (pendingBracket > 0) {
|
|
||||||
pendingBracket--;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else if (char == '(') {
|
|
||||||
pendingBracket++;
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (end > 0) url = url.substr(0, end);
|
|
||||||
if (url.endsWith('.')) url = url.substr(0, url.lastIndexOf('.'));
|
if (url.endsWith('.')) url = url.substr(0, url.lastIndexOf('.'));
|
||||||
if (url.endsWith(',')) url = url.substr(0, url.lastIndexOf(','));
|
if (url.endsWith(',')) url = url.substr(0, url.lastIndexOf(','));
|
||||||
return P.makeSuccess(i + url.length, url);
|
return P.makeSuccess(i + url.length, url);
|
||||||
|
@ -6,15 +6,24 @@ export default function(file: IDriveFile, thumbnail = false): string {
|
|||||||
|
|
||||||
if (file.metadata.withoutChunks) {
|
if (file.metadata.withoutChunks) {
|
||||||
if (thumbnail) {
|
if (thumbnail) {
|
||||||
return file.metadata.thumbnailUrl || file.metadata.url;
|
return file.metadata.thumbnailUrl || file.metadata.webpublicUrl || file.metadata.url;
|
||||||
} else {
|
} else {
|
||||||
return file.metadata.url;
|
return file.metadata.webpublicUrl || file.metadata.url;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (thumbnail) {
|
if (thumbnail) {
|
||||||
return `${config.drive_url}/${file._id}?thumbnail`;
|
return `${config.drive_url}/${file._id}?thumbnail`;
|
||||||
} else {
|
} else {
|
||||||
return `${config.drive_url}/${file._id}`;
|
return `${config.drive_url}/${file._id}?web`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getOriginalUrl(file: IDriveFile) {
|
||||||
|
if (file.metadata && file.metadata.url) {
|
||||||
|
return file.metadata.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
const accessKey = file.metadata ? file.metadata.accessKey : null;
|
||||||
|
return `${config.drive_url}/${file._id}${accessKey ? '?original=' + accessKey : ''}`;
|
||||||
|
}
|
||||||
|
29
src/models/drive-file-webpublic.ts
Normal file
29
src/models/drive-file-webpublic.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import * as mongo from 'mongodb';
|
||||||
|
import monkDb, { nativeDbConn } from '../db/mongodb';
|
||||||
|
|
||||||
|
const DriveFileWebpublic = monkDb.get<IDriveFileWebpublic>('driveFileWebpublics.files');
|
||||||
|
DriveFileWebpublic.createIndex('metadata.originalId', { sparse: true, unique: true });
|
||||||
|
export default DriveFileWebpublic;
|
||||||
|
|
||||||
|
export const DriveFileWebpublicChunk = monkDb.get('driveFileWebpublics.chunks');
|
||||||
|
|
||||||
|
export const getDriveFileWebpublicBucket = async (): Promise<mongo.GridFSBucket> => {
|
||||||
|
const db = await nativeDbConn();
|
||||||
|
const bucket = new mongo.GridFSBucket(db, {
|
||||||
|
bucketName: 'driveFileWebpublics'
|
||||||
|
});
|
||||||
|
return bucket;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type IMetadata = {
|
||||||
|
originalId: mongo.ObjectID;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type IDriveFileWebpublic = {
|
||||||
|
_id: mongo.ObjectID;
|
||||||
|
uploadDate: Date;
|
||||||
|
md5: string;
|
||||||
|
filename: string;
|
||||||
|
contentType: string;
|
||||||
|
metadata: IMetadata;
|
||||||
|
};
|
@ -3,7 +3,7 @@ const deepcopy = require('deepcopy');
|
|||||||
import { pack as packFolder } from './drive-folder';
|
import { pack as packFolder } from './drive-folder';
|
||||||
import monkDb, { nativeDbConn } from '../db/mongodb';
|
import monkDb, { nativeDbConn } from '../db/mongodb';
|
||||||
import isObjectId from '../misc/is-objectid';
|
import isObjectId from '../misc/is-objectid';
|
||||||
import getDriveFileUrl from '../misc/get-drive-file-url';
|
import getDriveFileUrl, { getOriginalUrl } from '../misc/get-drive-file-url';
|
||||||
|
|
||||||
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
|
const DriveFile = monkDb.get<IDriveFile>('driveFiles.files');
|
||||||
DriveFile.createIndex('md5');
|
DriveFile.createIndex('md5');
|
||||||
@ -28,21 +28,48 @@ export type IMetadata = {
|
|||||||
_user: any;
|
_user: any;
|
||||||
folderId: mongo.ObjectID;
|
folderId: mongo.ObjectID;
|
||||||
comment: string;
|
comment: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* リモートインスタンスから取得した場合の元URL
|
||||||
|
*/
|
||||||
uri?: string;
|
uri?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL for web(生成されている場合) or original
|
||||||
|
* * オブジェクトストレージを利用している or リモートサーバーへの直リンクである 場合のみ
|
||||||
|
*/
|
||||||
url?: string;
|
url?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL for thumbnail (thumbnailがなければなし)
|
||||||
|
* * オブジェクトストレージを利用している or リモートサーバーへの直リンクである 場合のみ
|
||||||
|
*/
|
||||||
thumbnailUrl?: string;
|
thumbnailUrl?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL for original (web用が生成されてない場合はurlがoriginalを指す)
|
||||||
|
* * オブジェクトストレージを利用している or リモートサーバーへの直リンクである 場合のみ
|
||||||
|
*/
|
||||||
|
webpublicUrl?: string;
|
||||||
|
|
||||||
|
accessKey?: string;
|
||||||
|
|
||||||
src?: string;
|
src?: string;
|
||||||
deletedAt?: Date;
|
deletedAt?: Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* このファイルの中身データがMongoDB内に保存されているのか否か
|
* このファイルの中身データがMongoDB内に保存されていないか否か
|
||||||
* オブジェクトストレージを利用している or リモートサーバーへの直リンクである
|
* オブジェクトストレージを利用している or リモートサーバーへの直リンクである
|
||||||
* な場合は false になります
|
* な場合は true になります
|
||||||
*/
|
*/
|
||||||
withoutChunks?: boolean;
|
withoutChunks?: boolean;
|
||||||
|
|
||||||
storage?: string;
|
storage?: string;
|
||||||
storageProps?: any;
|
|
||||||
|
/***
|
||||||
|
* ObjectStorage の格納先の情報
|
||||||
|
*/
|
||||||
|
storageProps?: IStorageProps;
|
||||||
isSensitive?: boolean;
|
isSensitive?: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,6 +83,25 @@ export type IMetadata = {
|
|||||||
isRemote?: boolean;
|
isRemote?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type IStorageProps = {
|
||||||
|
/**
|
||||||
|
* ObjectStorage key for original
|
||||||
|
*/
|
||||||
|
key: string;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* ObjectStorage key for thumbnail (thumbnailがなければなし)
|
||||||
|
*/
|
||||||
|
thumbnailKey?: string;
|
||||||
|
|
||||||
|
/***
|
||||||
|
* ObjectStorage key for webpublic (webpublicがなければなし)
|
||||||
|
*/
|
||||||
|
webpublicKey?: string;
|
||||||
|
|
||||||
|
id?: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type IDriveFile = {
|
export type IDriveFile = {
|
||||||
_id: mongo.ObjectID;
|
_id: mongo.ObjectID;
|
||||||
uploadDate: Date;
|
uploadDate: Date;
|
||||||
@ -83,7 +129,8 @@ export function validateFileName(name: string): boolean {
|
|||||||
export const packMany = (
|
export const packMany = (
|
||||||
files: any[],
|
files: any[],
|
||||||
options?: {
|
options?: {
|
||||||
detail: boolean
|
detail?: boolean
|
||||||
|
self?: boolean,
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
return Promise.all(files.map(f => pack(f, options)));
|
return Promise.all(files.map(f => pack(f, options)));
|
||||||
@ -95,11 +142,13 @@ export const packMany = (
|
|||||||
export const pack = (
|
export const pack = (
|
||||||
file: any,
|
file: any,
|
||||||
options?: {
|
options?: {
|
||||||
detail: boolean
|
detail?: boolean,
|
||||||
|
self?: boolean,
|
||||||
}
|
}
|
||||||
) => new Promise<any>(async (resolve, reject) => {
|
) => new Promise<any>(async (resolve, reject) => {
|
||||||
const opts = Object.assign({
|
const opts = Object.assign({
|
||||||
detail: false
|
detail: false,
|
||||||
|
self: false
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
let _file: any;
|
let _file: any;
|
||||||
@ -165,5 +214,9 @@ export const pack = (
|
|||||||
delete _target.isRemote;
|
delete _target.isRemote;
|
||||||
delete _target._user;
|
delete _target._user;
|
||||||
|
|
||||||
|
if (opts.self) {
|
||||||
|
_target.url = getOriginalUrl(_file);
|
||||||
|
}
|
||||||
|
|
||||||
resolve(_target);
|
resolve(_target);
|
||||||
});
|
});
|
||||||
|
@ -77,5 +77,5 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||||||
sort: sort
|
sort: sort
|
||||||
});
|
});
|
||||||
|
|
||||||
res(await packMany(files));
|
res(await packMany(files, { detail: false, self: true }));
|
||||||
}));
|
}));
|
||||||
|
@ -32,6 +32,6 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||||||
if (file === null) {
|
if (file === null) {
|
||||||
res({ file: null });
|
res({ file: null });
|
||||||
} else {
|
} else {
|
||||||
res({ file: await pack(file) });
|
res({ file: await pack(file, { self: true }) });
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -74,7 +74,7 @@ export default define(meta, (ps, user, app, file, cleanup) => new Promise(async
|
|||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
res(pack(driveFile));
|
res(pack(driveFile, { self: true }));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|
||||||
|
@ -31,5 +31,5 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||||||
'metadata.folderId': ps.folderId
|
'metadata.folderId': ps.folderId
|
||||||
});
|
});
|
||||||
|
|
||||||
res(await Promise.all(files.map(file => pack(file))));
|
res(await Promise.all(files.map(file => pack(file, { self: true }))));
|
||||||
}));
|
}));
|
||||||
|
@ -41,7 +41,8 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
const _file = await pack(file, {
|
const _file = await pack(file, {
|
||||||
detail: true
|
detail: true,
|
||||||
|
self: true
|
||||||
});
|
});
|
||||||
|
|
||||||
res(_file);
|
res(_file);
|
||||||
|
@ -111,7 +111,7 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
const fileObj = await pack(file);
|
const fileObj = await pack(file, { self: true });
|
||||||
|
|
||||||
// Response
|
// Response
|
||||||
res(fileObj);
|
res(fileObj);
|
||||||
|
@ -50,5 +50,5 @@ export const meta = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||||
res(pack(await uploadFromUrl(ps.url, user, ps.folderId, null, ps.isSensitive, ps.force)));
|
res(pack(await uploadFromUrl(ps.url, user, ps.folderId, null, ps.isSensitive, ps.force), { self: true }));
|
||||||
}));
|
}));
|
||||||
|
@ -65,5 +65,5 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|||||||
sort: sort
|
sort: sort
|
||||||
});
|
});
|
||||||
|
|
||||||
res(await packMany(files));
|
res(await packMany(files, { self: true }));
|
||||||
}));
|
}));
|
||||||
|
@ -19,6 +19,12 @@ app.use(cors({
|
|||||||
origin: '*'
|
origin: '*'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// No caching
|
||||||
|
app.use(async (ctx, next) => {
|
||||||
|
ctx.set('Cache-Control', 'private, max-age=0, must-revalidate');
|
||||||
|
await next();
|
||||||
|
});
|
||||||
|
|
||||||
app.use(bodyParser({
|
app.use(bodyParser({
|
||||||
// リクエストが multipart/form-data でない限りはJSONだと見なす
|
// リクエストが multipart/form-data でない限りはJSONだと見なす
|
||||||
detectJSON: ctx => !ctx.is('multipart/form-data')
|
detectJSON: ctx => !ctx.is('multipart/form-data')
|
||||||
|
@ -3,6 +3,7 @@ import * as send from 'koa-send';
|
|||||||
import * as mongodb from 'mongodb';
|
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';
|
||||||
|
import DriveFileWebpublic, { getDriveFileWebpublicBucket } from '../../models/drive-file-webpublic';
|
||||||
|
|
||||||
const assets = `${__dirname}/../../server/file/assets/`;
|
const assets = `${__dirname}/../../server/file/assets/`;
|
||||||
|
|
||||||
@ -41,6 +42,11 @@ export default async function(ctx: Koa.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sendRaw = async () => {
|
const sendRaw = async () => {
|
||||||
|
if (file.metadata && file.metadata.accessKey && file.metadata.accessKey != ctx.query['original']) {
|
||||||
|
ctx.status = 403;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const bucket = await getDriveFileBucket();
|
const bucket = await getDriveFileBucket();
|
||||||
const readable = bucket.openDownloadStream(fileId);
|
const readable = bucket.openDownloadStream(fileId);
|
||||||
readable.on('error', commonReadableHandlerGenerator(ctx));
|
readable.on('error', commonReadableHandlerGenerator(ctx));
|
||||||
@ -60,6 +66,19 @@ export default async function(ctx: Koa.Context) {
|
|||||||
} else {
|
} else {
|
||||||
await sendRaw();
|
await sendRaw();
|
||||||
}
|
}
|
||||||
|
} else if ('web' in ctx.query) {
|
||||||
|
const web = await DriveFileWebpublic.findOne({
|
||||||
|
'metadata.originalId': fileId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (web != null) {
|
||||||
|
ctx.set('Content-Type', file.contentType);
|
||||||
|
|
||||||
|
const bucket = await getDriveFileWebpublicBucket();
|
||||||
|
ctx.body = bucket.openDownloadStream(web._id);
|
||||||
|
} else {
|
||||||
|
await sendRaw();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ('download' in ctx.query) {
|
if ('download' in ctx.query) {
|
||||||
ctx.set('Content-Disposition', 'attachment');
|
ctx.set('Content-Disposition', 'attachment');
|
||||||
|
@ -59,6 +59,11 @@ const router = new Router();
|
|||||||
router.use(activityPub.routes());
|
router.use(activityPub.routes());
|
||||||
router.use(webFinger.routes());
|
router.use(webFinger.routes());
|
||||||
|
|
||||||
|
// Return 404 for other .well-known
|
||||||
|
router.all('/.well-known/*', async ctx => {
|
||||||
|
ctx.status = 404;
|
||||||
|
});
|
||||||
|
|
||||||
// Register router
|
// Register router
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import { publishMainStream, publishDriveStream } from '../../stream';
|
|||||||
import { isLocalUser, IUser, IRemoteUser } from '../../models/user';
|
import { isLocalUser, IUser, IRemoteUser } from '../../models/user';
|
||||||
import delFile from './delete-file';
|
import delFile from './delete-file';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
|
import { getDriveFileWebpublicBucket } from '../../models/drive-file-webpublic';
|
||||||
import { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
|
import { getDriveFileThumbnailBucket } from '../../models/drive-file-thumbnail';
|
||||||
import driveChart from '../../chart/drive';
|
import driveChart from '../../chart/drive';
|
||||||
import perUserDriveChart from '../../chart/per-user-drive';
|
import perUserDriveChart from '../../chart/per-user-drive';
|
||||||
@ -23,7 +24,71 @@ import fetchMeta from '../../misc/fetch-meta';
|
|||||||
|
|
||||||
const log = debug('misskey:drive:add-file');
|
const log = debug('misskey:drive:add-file');
|
||||||
|
|
||||||
async function save(path: string, name: string, type: string, hash: string, size: number, metadata: any): Promise<IDriveFile> {
|
/***
|
||||||
|
* Save file
|
||||||
|
* @param path Path for original
|
||||||
|
* @param name Name for original
|
||||||
|
* @param type Content-Type for original
|
||||||
|
* @param hash Hash for original
|
||||||
|
* @param size Size for original
|
||||||
|
* @param metadata
|
||||||
|
*/
|
||||||
|
async function save(path: string, name: string, type: string, hash: string, size: number, metadata: IMetadata): Promise<IDriveFile> {
|
||||||
|
// #region webpublic
|
||||||
|
let webpublic: Buffer;
|
||||||
|
let webpublicExt = 'jpg';
|
||||||
|
let webpublicType = 'image/jpeg';
|
||||||
|
|
||||||
|
if (!metadata.uri) { // from local instance
|
||||||
|
log(`creating web image`);
|
||||||
|
|
||||||
|
if (['image/jpeg'].includes(type)) {
|
||||||
|
webpublic = await sharp(path)
|
||||||
|
.resize(2048, 2048, {
|
||||||
|
fit: 'inside',
|
||||||
|
withoutEnlargement: true
|
||||||
|
})
|
||||||
|
.rotate()
|
||||||
|
.jpeg({
|
||||||
|
quality: 85,
|
||||||
|
progressive: true
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
} else if (['image/webp'].includes(type)) {
|
||||||
|
webpublic = await sharp(path)
|
||||||
|
.resize(2048, 2048, {
|
||||||
|
fit: 'inside',
|
||||||
|
withoutEnlargement: true
|
||||||
|
})
|
||||||
|
.rotate()
|
||||||
|
.webp({
|
||||||
|
quality: 85
|
||||||
|
})
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
webpublicExt = 'webp';
|
||||||
|
webpublicType = 'image/webp';
|
||||||
|
} else if (['image/png'].includes(type)) {
|
||||||
|
webpublic = await sharp(path)
|
||||||
|
.resize(2048, 2048, {
|
||||||
|
fit: 'inside',
|
||||||
|
withoutEnlargement: true
|
||||||
|
})
|
||||||
|
.rotate()
|
||||||
|
.png()
|
||||||
|
.toBuffer();
|
||||||
|
|
||||||
|
webpublicExt = 'png';
|
||||||
|
webpublicType = 'image/png';
|
||||||
|
} else {
|
||||||
|
log(`web image not created (not an image)`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log(`web image not created (from remote)`);
|
||||||
|
}
|
||||||
|
// #endregion webpublic
|
||||||
|
|
||||||
|
// #region thumbnail
|
||||||
let thumbnail: Buffer;
|
let thumbnail: Buffer;
|
||||||
let thumbnailExt = 'jpg';
|
let thumbnailExt = 'jpg';
|
||||||
let thumbnailType = 'image/jpeg';
|
let thumbnailType = 'image/jpeg';
|
||||||
@ -53,10 +118,9 @@ async function save(path: string, name: string, type: string, hash: string, size
|
|||||||
thumbnailExt = 'png';
|
thumbnailExt = 'png';
|
||||||
thumbnailType = 'image/png';
|
thumbnailType = 'image/png';
|
||||||
}
|
}
|
||||||
|
// #endregion thumbnail
|
||||||
|
|
||||||
if (config.drive && config.drive.storage == 'minio') {
|
if (config.drive && config.drive.storage == 'minio') {
|
||||||
const minio = new Minio.Client(config.drive.config);
|
|
||||||
|
|
||||||
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
|
let [ext] = (name.match(/\.([a-zA-Z0-9_-]+)$/) || ['']);
|
||||||
|
|
||||||
if (ext === '') {
|
if (ext === '') {
|
||||||
@ -66,33 +130,41 @@ async function save(path: string, name: string, type: string, hash: string, size
|
|||||||
}
|
}
|
||||||
|
|
||||||
const key = `${config.drive.prefix}/${uuid.v4()}${ext}`;
|
const key = `${config.drive.prefix}/${uuid.v4()}${ext}`;
|
||||||
|
const webpublicKey = `${config.drive.prefix}/${uuid.v4()}.${webpublicExt}`;
|
||||||
const thumbnailKey = `${config.drive.prefix}/${uuid.v4()}.${thumbnailExt}`;
|
const thumbnailKey = `${config.drive.prefix}/${uuid.v4()}.${thumbnailExt}`;
|
||||||
|
|
||||||
|
log(`uploading original: ${key}`);
|
||||||
|
const uploads = [
|
||||||
|
upload(key, fs.createReadStream(path), type)
|
||||||
|
];
|
||||||
|
|
||||||
|
if (webpublic) {
|
||||||
|
log(`uploading webpublic: ${webpublicKey}`);
|
||||||
|
uploads.push(upload(webpublicKey, webpublic, webpublicType));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thumbnail) {
|
||||||
|
log(`uploading thumbnail: ${thumbnailKey}`);
|
||||||
|
uploads.push(upload(thumbnailKey, thumbnail, thumbnailType));
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(uploads);
|
||||||
|
|
||||||
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 }`;
|
||||||
|
|
||||||
await minio.putObject(config.drive.bucket, key, fs.createReadStream(path), size, {
|
|
||||||
'Content-Type': type,
|
|
||||||
'Cache-Control': 'max-age=31536000, immutable'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (thumbnail) {
|
|
||||||
await minio.putObject(config.drive.bucket, thumbnailKey, thumbnail, size, {
|
|
||||||
'Content-Type': thumbnailType,
|
|
||||||
'Cache-Control': 'max-age=31536000, immutable'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.assign(metadata, {
|
Object.assign(metadata, {
|
||||||
withoutChunks: true,
|
withoutChunks: true,
|
||||||
storage: 'minio',
|
storage: 'minio',
|
||||||
storageProps: {
|
storageProps: {
|
||||||
key: key,
|
key: key,
|
||||||
thumbnailKey: thumbnailKey
|
webpublicKey: webpublic ? webpublicKey : null,
|
||||||
|
thumbnailKey: thumbnail ? thumbnailKey : null,
|
||||||
},
|
},
|
||||||
url: `${ baseUrl }/${ key }`,
|
url: `${ baseUrl }/${ key }`,
|
||||||
|
webpublicUrl: webpublic ? `${ baseUrl }/${ webpublicKey }` : null,
|
||||||
thumbnailUrl: thumbnail ? `${ baseUrl }/${ thumbnailKey }` : null
|
thumbnailUrl: thumbnail ? `${ baseUrl }/${ thumbnailKey }` : null
|
||||||
});
|
} as IMetadata);
|
||||||
|
|
||||||
const file = await DriveFile.insert({
|
const file = await DriveFile.insert({
|
||||||
length: size,
|
length: size,
|
||||||
@ -105,29 +177,55 @@ async function save(path: string, name: string, type: string, hash: string, size
|
|||||||
|
|
||||||
return file;
|
return file;
|
||||||
} else {
|
} else {
|
||||||
// Get MongoDB GridFS bucket
|
// #region store original
|
||||||
const bucket = await getDriveFileBucket();
|
const originalDst = await getDriveFileBucket();
|
||||||
|
|
||||||
const file = await new Promise<IDriveFile>((resolve, reject) => {
|
// web用(Exif削除済み)がある場合はオリジナルにアクセス制限
|
||||||
const writeStream = bucket.openUploadStream(name, {
|
if (webpublic) metadata.accessKey = uuid.v4();
|
||||||
|
|
||||||
|
const originalFile = await new Promise<IDriveFile>((resolve, reject) => {
|
||||||
|
const writeStream = originalDst.openUploadStream(name, {
|
||||||
contentType: type,
|
contentType: type,
|
||||||
metadata
|
metadata
|
||||||
});
|
});
|
||||||
|
|
||||||
writeStream.once('finish', resolve);
|
writeStream.once('finish', resolve);
|
||||||
writeStream.on('error', reject);
|
writeStream.on('error', reject);
|
||||||
|
|
||||||
fs.createReadStream(path).pipe(writeStream);
|
fs.createReadStream(path).pipe(writeStream);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log(`original stored to ${originalFile._id}`);
|
||||||
|
// #endregion store original
|
||||||
|
|
||||||
|
// #region store webpublic
|
||||||
|
if (webpublic) {
|
||||||
|
const webDst = await getDriveFileWebpublicBucket();
|
||||||
|
|
||||||
|
const webFile = await new Promise<IDriveFile>((resolve, reject) => {
|
||||||
|
const writeStream = webDst.openUploadStream(name, {
|
||||||
|
contentType: webpublicType,
|
||||||
|
metadata: {
|
||||||
|
originalId: originalFile._id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
writeStream.once('finish', resolve);
|
||||||
|
writeStream.on('error', reject);
|
||||||
|
writeStream.end(webpublic);
|
||||||
|
});
|
||||||
|
|
||||||
|
log(`web stored ${webFile._id}`);
|
||||||
|
}
|
||||||
|
// #endregion store webpublic
|
||||||
|
|
||||||
if (thumbnail) {
|
if (thumbnail) {
|
||||||
const thumbnailBucket = await getDriveFileThumbnailBucket();
|
const thumbnailBucket = await getDriveFileThumbnailBucket();
|
||||||
|
|
||||||
await new Promise<IDriveFile>((resolve, reject) => {
|
const tuhmFile = await new Promise<IDriveFile>((resolve, reject) => {
|
||||||
const writeStream = thumbnailBucket.openUploadStream(name, {
|
const writeStream = thumbnailBucket.openUploadStream(name, {
|
||||||
contentType: thumbnailType,
|
contentType: thumbnailType,
|
||||||
metadata: {
|
metadata: {
|
||||||
originalId: file._id
|
originalId: originalFile._id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -135,12 +233,23 @@ async function save(path: string, name: string, type: string, hash: string, size
|
|||||||
writeStream.on('error', reject);
|
writeStream.on('error', reject);
|
||||||
writeStream.end(thumbnail);
|
writeStream.end(thumbnail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
log(`thumbnail stored ${tuhmFile._id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return file;
|
return originalFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function upload(key: string, stream: fs.ReadStream | Buffer, type: string) {
|
||||||
|
const minio = new Minio.Client(config.drive.config);
|
||||||
|
|
||||||
|
await minio.putObject(config.drive.bucket, key, stream, null, {
|
||||||
|
'Content-Type': type,
|
||||||
|
'Cache-Control': 'max-age=31536000, immutable'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function deleteOldFile(user: IRemoteUser) {
|
async function deleteOldFile(user: IRemoteUser) {
|
||||||
const oldFile = await DriveFile.findOne({
|
const oldFile = await DriveFile.findOne({
|
||||||
_id: {
|
_id: {
|
||||||
|
@ -4,6 +4,7 @@ import DriveFileThumbnail, { DriveFileThumbnailChunk } from '../../models/drive-
|
|||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import driveChart from '../../chart/drive';
|
import driveChart from '../../chart/drive';
|
||||||
import perUserDriveChart from '../../chart/per-user-drive';
|
import perUserDriveChart from '../../chart/per-user-drive';
|
||||||
|
import DriveFileWebpublic, { DriveFileWebpublicChunk } from '../../models/drive-file-webpublic';
|
||||||
|
|
||||||
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') {
|
||||||
@ -20,6 +21,11 @@ export default async function(file: IDriveFile, isExpired = false) {
|
|||||||
const thumbnailObj = file.metadata.storageProps.thumbnailKey ? file.metadata.storageProps.thumbnailKey : `${config.drive.prefix}/${file.metadata.storageProps.id}-thumbnail`;
|
const thumbnailObj = file.metadata.storageProps.thumbnailKey ? file.metadata.storageProps.thumbnailKey : `${config.drive.prefix}/${file.metadata.storageProps.id}-thumbnail`;
|
||||||
await minio.removeObject(config.drive.bucket, thumbnailObj);
|
await minio.removeObject(config.drive.bucket, thumbnailObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (file.metadata.webpublicUrl) {
|
||||||
|
const webpublicObj = file.metadata.storageProps.webpublicKey ? file.metadata.storageProps.webpublicKey : `${config.drive.prefix}/${file.metadata.storageProps.id}-original`;
|
||||||
|
await minio.removeObject(config.drive.bucket, webpublicObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// チャンクをすべて削除
|
// チャンクをすべて削除
|
||||||
@ -48,6 +54,20 @@ export default async function(file: IDriveFile, isExpired = false) {
|
|||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
//#region Web公開用もあれば削除
|
||||||
|
const webpublic = await DriveFileWebpublic.findOne({
|
||||||
|
'metadata.originalId': file._id
|
||||||
|
});
|
||||||
|
|
||||||
|
if (webpublic) {
|
||||||
|
await DriveFileWebpublicChunk.remove({
|
||||||
|
files_id: webpublic._id
|
||||||
|
});
|
||||||
|
|
||||||
|
await DriveFileWebpublic.remove({ _id: webpublic._id });
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
// 統計を更新
|
// 統計を更新
|
||||||
driveChart.update(file, false);
|
driveChart.update(file, false);
|
||||||
perUserDriveChart.update(file, false);
|
perUserDriveChart.update(file, false);
|
||||||
|
20
test/mfm.ts
20
test/mfm.ts
@ -449,6 +449,15 @@ describe('Text', () => {
|
|||||||
], tokens);
|
], tokens);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('simple (with silent flag)', () => {
|
||||||
|
const tokens = analyze('?[foo](https://example.com)');
|
||||||
|
assert.deepEqual([
|
||||||
|
nodeWithChildren('link', [
|
||||||
|
text('foo')
|
||||||
|
], { url: 'https://example.com', silent: true })
|
||||||
|
], tokens);
|
||||||
|
});
|
||||||
|
|
||||||
it('in text', () => {
|
it('in text', () => {
|
||||||
const tokens = analyze('before[foo](https://example.com)after');
|
const tokens = analyze('before[foo](https://example.com)after');
|
||||||
assert.deepEqual([
|
assert.deepEqual([
|
||||||
@ -632,6 +641,17 @@ describe('Text', () => {
|
|||||||
], tokens);
|
], tokens);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('center', () => {
|
||||||
|
it('simple', () => {
|
||||||
|
const tokens = analyze('<center>foo</center>');
|
||||||
|
assert.deepEqual([
|
||||||
|
nodeWithChildren('center', [
|
||||||
|
text('foo')
|
||||||
|
]),
|
||||||
|
], tokens);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toHtml', () => {
|
describe('toHtml', () => {
|
||||||
|
Reference in New Issue
Block a user