diff options
Diffstat (limited to 'src/misc')
| -rw-r--r-- | src/misc/acct/parse.ts | 5 | ||||
| -rw-r--r-- | src/misc/environmentInfo.ts | 17 | ||||
| -rw-r--r-- | src/misc/extract-emojis.ts | 9 | ||||
| -rw-r--r-- | src/misc/extract-hashtags.ts | 9 | ||||
| -rw-r--r-- | src/misc/extract-mentions.ts | 10 | ||||
| -rw-r--r-- | src/misc/fetch-meta.ts | 8 | ||||
| -rw-r--r-- | src/misc/get-drive-file-url.ts | 15 | ||||
| -rw-r--r-- | src/misc/get-note-summary.ts | 14 | ||||
| -rw-r--r-- | src/misc/machineInfo.ts | 17 |
9 files changed, 59 insertions, 45 deletions
diff --git a/src/misc/acct/parse.ts b/src/misc/acct/parse.ts index 0c00fccef6..b120746650 100644 --- a/src/misc/acct/parse.ts +++ b/src/misc/acct/parse.ts @@ -1,4 +1,5 @@ export default (acct: string) => { - const splitted = acct.split('@', 2); - return { username: splitted[0], host: splitted[1] || null }; + if (acct.startsWith('@')) acct = acct.substr(1); + const split = acct.split('@', 2); + return { username: split[0], host: split[1] || null }; }; diff --git a/src/misc/environmentInfo.ts b/src/misc/environmentInfo.ts deleted file mode 100644 index cee42ef9c0..0000000000 --- a/src/misc/environmentInfo.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Logger from './logger'; -import isRoot = require('is-root'); - -export default class { - public static show(): void { - const env = process.env.NODE_ENV; - const logger = new Logger('Env'); - logger.info(typeof env == 'undefined' ? 'NODE_ENV is not set' : `NODE_ENV: ${env}`); - - if (env !== 'production') { - logger.warn('The environment is not in production mode'); - logger.warn('Do not use for production purpose'); - } - - logger.info(`You ${isRoot() ? '' : 'do not '}have root privileges`); - } -} diff --git a/src/misc/extract-emojis.ts b/src/misc/extract-emojis.ts new file mode 100644 index 0000000000..a7b949f4f7 --- /dev/null +++ b/src/misc/extract-emojis.ts @@ -0,0 +1,9 @@ +import { EmojiNode, MfmForest } from '../mfm/parser'; +import { preorderF } from '../prelude/tree'; +import { unique } from '../prelude/array'; + +export default function(mfmForest: MfmForest): string[] { + const emojiNodes = preorderF(mfmForest).filter(x => x.type === 'emoji') as EmojiNode[]; + const emojis = emojiNodes.filter(x => x.props.name && x.props.name.length <= 100).map(x => x.props.name); + return unique(emojis); +} diff --git a/src/misc/extract-hashtags.ts b/src/misc/extract-hashtags.ts new file mode 100644 index 0000000000..43eaa45909 --- /dev/null +++ b/src/misc/extract-hashtags.ts @@ -0,0 +1,9 @@ +import { HashtagNode, MfmForest } from '../mfm/parser'; +import { preorderF } from '../prelude/tree'; +import { unique } from '../prelude/array'; + +export default function(mfmForest: MfmForest): string[] { + const hashtagNodes = preorderF(mfmForest).filter(x => x.type === 'hashtag') as HashtagNode[]; + const hashtags = hashtagNodes.map(x => x.props.hashtag); + return unique(hashtags); +} diff --git a/src/misc/extract-mentions.ts b/src/misc/extract-mentions.ts new file mode 100644 index 0000000000..a53a25ffc4 --- /dev/null +++ b/src/misc/extract-mentions.ts @@ -0,0 +1,10 @@ +// test is located in test/extract-mentions + +import { MentionNode, MfmForest } from '../mfm/parser'; +import { preorderF } from '../prelude/tree'; + +export default function(mfmForest: MfmForest): MentionNode['props'][] { + // TODO: 重複を削除 + const mentionNodes = preorderF(mfmForest).filter(x => x.type === 'mention') as MentionNode[]; + return mentionNodes.map(x => x.props); +} diff --git a/src/misc/fetch-meta.ts b/src/misc/fetch-meta.ts index e855097c42..e6488da395 100644 --- a/src/misc/fetch-meta.ts +++ b/src/misc/fetch-meta.ts @@ -15,7 +15,13 @@ const defaultMeta: any = { maxNoteTextLength: 1000, enableTwitterIntegration: false, enableGithubIntegration: false, - enableDiscordIntegration: false + enableDiscordIntegration: false, + enableExternalUserRecommendation: false, + externalUserRecommendationEngine: 'https://vinayaka.distsn.org/cgi-bin/vinayaka-user-match-misskey-api.cgi?{{host}}+{{user}}+{{limit}}+{{offset}}', + externalUserRecommendationTimeout: 300000, + mascotImageUrl: '/assets/ai.png', + errorImageUrl: 'https://ai.misskey.xyz/aiart/yubitun.png', + enableServiceWorker: false }; export default async function(): Promise<IMeta> { diff --git a/src/misc/get-drive-file-url.ts b/src/misc/get-drive-file-url.ts index 0fe467261e..6ab7bfdb1b 100644 --- a/src/misc/get-drive-file-url.ts +++ b/src/misc/get-drive-file-url.ts @@ -6,15 +6,24 @@ export default function(file: IDriveFile, thumbnail = false): string { if (file.metadata.withoutChunks) { if (thumbnail) { - return file.metadata.thumbnailUrl || file.metadata.url; + return file.metadata.thumbnailUrl || file.metadata.webpublicUrl || file.metadata.url; } else { - return file.metadata.url; + return file.metadata.webpublicUrl || file.metadata.url; } } else { if (thumbnail) { return `${config.drive_url}/${file._id}?thumbnail`; } 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 : ''}`; +} diff --git a/src/misc/get-note-summary.ts b/src/misc/get-note-summary.ts index 3f96483032..e3458cb189 100644 --- a/src/misc/get-note-summary.ts +++ b/src/misc/get-note-summary.ts @@ -14,7 +14,11 @@ const summarize = (note: any): string => { let summary = ''; // 本文 - summary += note.text ? note.text : ''; + if (note.cw != null) { + summary += note.cw; + } else { + summary += note.text ? note.text : ''; + } // ファイルが添付されているとき if ((note.files || []).length != 0) { @@ -29,18 +33,18 @@ const summarize = (note: any): string => { // 返信のとき if (note.replyId) { if (note.reply) { - summary += ` RE: ${summarize(note.reply)}`; + summary += `\n\nRE: ${summarize(note.reply)}`; } else { - summary += ' RE: ...'; + summary += '\n\nRE: ...'; } } // Renoteのとき if (note.renoteId) { if (note.renote) { - summary += ` RN: ${summarize(note.renote)}`; + summary += `\n\nRN: ${summarize(note.renote)}`; } else { - summary += ' RN: ...'; + summary += '\n\nRN: ...'; } } diff --git a/src/misc/machineInfo.ts b/src/misc/machineInfo.ts deleted file mode 100644 index 7d8a52ff9a..0000000000 --- a/src/misc/machineInfo.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as os from 'os'; -import Logger from './logger'; -import * as sysUtils from 'systeminformation'; - -export default class { - public static async show() { - const logger = new Logger('Machine'); - logger.info(`Hostname: ${os.hostname()}`); - logger.info(`Platform: ${process.platform}`); - logger.info(`Architecture: ${process.arch}`); - logger.info(`CPU: ${os.cpus().length} core`); - const mem = await sysUtils.mem(); - const totalmem = (mem.total / 1024 / 1024 / 1024).toFixed(1); - const availmem = (mem.available / 1024 / 1024 / 1024).toFixed(1); - logger.info(`MEM: ${totalmem}GB (available: ${availmem}GB)`); - } -} |