mirror of
https://github.com/syuilo/ai.git
synced 2024-11-21 12:47:59 +00:00
✌️ (#131)
* fix(process): 何か失敗してもクラッシュしないように * fix(upload): ファイルのアップロードができない問題を修正 * fix(docker): ビルドできるように
This commit is contained in:
parent
54f10b3321
commit
465b4312dc
|
@ -1,6 +1,6 @@
|
||||||
FROM node:lts-bullseye
|
FROM node:lts
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y tini
|
RUN apt-get update && apt-get install tini --no-install-recommends -y && apt-get clean && rm -rf /var/lib/apt-get/lists/*
|
||||||
|
|
||||||
ARG enable_mecab=1
|
ARG enable_mecab=1
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ RUN if [ $enable_mecab -ne 0 ]; then apt-get update \
|
||||||
COPY . /ai
|
COPY . /ai
|
||||||
|
|
||||||
WORKDIR /ai
|
WORKDIR /ai
|
||||||
RUN npm install && npm run build
|
RUN npm install && npm run build || test -f ./built/index.js
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/bin/tini", "--"]
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||||
CMD npm start
|
CMD npm start
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
"@types/ws": "8.5.10",
|
"@types/ws": "8.5.10",
|
||||||
"canvas": "2.11.2",
|
"canvas": "2.11.2",
|
||||||
"chalk": "5.3.0",
|
"chalk": "5.3.0",
|
||||||
|
"formdata-node": "6.0.3",
|
||||||
"got": "14.0.0",
|
"got": "14.0.0",
|
||||||
"lokijs": "1.5.12",
|
"lokijs": "1.5.12",
|
||||||
"memory-streams": "0.1.3",
|
"memory-streams": "0.1.3",
|
||||||
|
@ -28,7 +29,6 @@
|
||||||
"promise-retry": "2.0.1",
|
"promise-retry": "2.0.1",
|
||||||
"random-seed": "0.3.0",
|
"random-seed": "0.3.0",
|
||||||
"reconnecting-websocket": "4.4.0",
|
"reconnecting-websocket": "4.4.0",
|
||||||
"request": "2.88.2",
|
|
||||||
"seedrandom": "3.0.5",
|
"seedrandom": "3.0.5",
|
||||||
"ts-patch": "3.1.2",
|
"ts-patch": "3.1.2",
|
||||||
"twemoji-parser": "14.0.0",
|
"twemoji-parser": "14.0.0",
|
||||||
|
|
18
src/ai.ts
18
src/ai.ts
|
@ -4,6 +4,7 @@ import * as fs from 'fs';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import loki from 'lokijs';
|
import loki from 'lokijs';
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
import { FormData, File } from 'formdata-node';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ import config from '@/config.js';
|
||||||
import Module from '@/module.js';
|
import Module from '@/module.js';
|
||||||
import Message from '@/message.js';
|
import Message from '@/message.js';
|
||||||
import Friend, { FriendDoc } from '@/friend.js';
|
import Friend, { FriendDoc } from '@/friend.js';
|
||||||
import { User } from '@/misskey/user.js';
|
import type { User } from '@/misskey/user.js';
|
||||||
import Stream from '@/stream.js';
|
import Stream from '@/stream.js';
|
||||||
import log from '@/utils/log.js';
|
import log from '@/utils/log.js';
|
||||||
import { sleep } from './utils/sleep.js';
|
import { sleep } from './utils/sleep.js';
|
||||||
|
@ -343,17 +344,14 @@ export default class 藍 {
|
||||||
* ファイルをドライブにアップロードします
|
* ファイルをドライブにアップロードします
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async upload(file: Buffer | fs.ReadStream, meta: any) {
|
public async upload(file: Buffer | fs.ReadStream, meta: { filename: string, contentType: string }) {
|
||||||
|
const form = new FormData();
|
||||||
|
form.set('i', config.i);
|
||||||
|
form.set('file', new File([file], meta.filename, { type: meta.contentType }));
|
||||||
|
|
||||||
const res = await got.post({
|
const res = await got.post({
|
||||||
url: `${config.apiUrl}/drive/files/create`,
|
url: `${config.apiUrl}/drive/files/create`,
|
||||||
formData: {
|
body: form
|
||||||
i: config.i,
|
|
||||||
file: {
|
|
||||||
value: file,
|
|
||||||
options: meta
|
|
||||||
}
|
|
||||||
},
|
|
||||||
json: true
|
|
||||||
}).json();
|
}).json();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { bindThis } from '@/decorators.js';
|
||||||
import 藍 from '@/ai.js';
|
import 藍 from '@/ai.js';
|
||||||
import IModule from '@/module.js';
|
import IModule from '@/module.js';
|
||||||
import getDate from '@/utils/get-date.js';
|
import getDate from '@/utils/get-date.js';
|
||||||
import { User } from '@/misskey/user.js';
|
import type { User } from '@/misskey/user.js';
|
||||||
import { genItem } from '@/vocabulary.js';
|
import { genItem } from '@/vocabulary.js';
|
||||||
|
|
||||||
export type FriendDoc = {
|
export type FriendDoc = {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// AiOS bootstrapper
|
// AiOS bootstrapper
|
||||||
|
|
||||||
|
import process from 'node:process';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
import promiseRetry from 'promise-retry';
|
import promiseRetry from 'promise-retry';
|
||||||
|
@ -45,6 +46,13 @@ function log(msg: string): void {
|
||||||
|
|
||||||
log(chalk.bold(`Ai v${pkg._v}`));
|
log(chalk.bold(`Ai v${pkg._v}`));
|
||||||
|
|
||||||
|
process.on('uncaughtException', err => {
|
||||||
|
try {
|
||||||
|
console.error(`Uncaught exception: ${err.message}`);
|
||||||
|
console.dir(err, { colors: true, depth: 2 });
|
||||||
|
} catch { }
|
||||||
|
});
|
||||||
|
|
||||||
promiseRetry(retry => {
|
promiseRetry(retry => {
|
||||||
log(`Account fetching... ${chalk.gray(config.host)}`);
|
log(`Account fetching... ${chalk.gray(config.host)}`);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import chalk from 'chalk';
|
||||||
|
|
||||||
import 藍 from '@/ai.js';
|
import 藍 from '@/ai.js';
|
||||||
import Friend from '@/friend.js';
|
import Friend from '@/friend.js';
|
||||||
import { User } from '@/misskey/user.js';
|
import type { User } from '@/misskey/user.js';
|
||||||
import includes from '@/utils/includes.js';
|
import includes from '@/utils/includes.js';
|
||||||
import or from '@/utils/or.js';
|
import or from '@/utils/or.js';
|
||||||
import config from '@/config.js';
|
import config from '@/config.js';
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { parse } from 'twemoji-parser';
|
import { parse } from 'twemoji-parser';
|
||||||
|
|
||||||
import { Note } from '@/misskey/note.js';
|
import type { Note } from '@/misskey/note.js';
|
||||||
import Module from '@/module.js';
|
import Module from '@/module.js';
|
||||||
import Stream from '@/stream.js';
|
import Stream from '@/stream.js';
|
||||||
import includes from '@/utils/includes.js';
|
import includes from '@/utils/includes.js';
|
||||||
import { sleep } from '../../utils/sleep.js';
|
import { sleep } from '@/utils/sleep.js';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'emoji-react';
|
public readonly name = 'emoji-react';
|
||||||
|
|
|
@ -3,7 +3,7 @@ import loki from 'lokijs';
|
||||||
import Module from '@/module.js';
|
import Module from '@/module.js';
|
||||||
import Message from '@/message.js';
|
import Message from '@/message.js';
|
||||||
import serifs from '@/serifs.js';
|
import serifs from '@/serifs.js';
|
||||||
import { User } from '@/misskey/user.js';
|
import type { User } from '@/misskey/user.js';
|
||||||
import { acct } from '@/utils/acct.js';
|
import { acct } from '@/utils/acct.js';
|
||||||
|
|
||||||
type Game = {
|
type Game = {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Module from '@/module.js';
|
||||||
import serifs from '@/serifs.js';
|
import serifs from '@/serifs.js';
|
||||||
import { genItem } from '@/vocabulary.js';
|
import { genItem } from '@/vocabulary.js';
|
||||||
import config from '@/config.js';
|
import config from '@/config.js';
|
||||||
import { Note } from '@/misskey/note.js';
|
import type { Note } from '@/misskey/note.js';
|
||||||
|
|
||||||
export default class extends Module {
|
export default class extends Module {
|
||||||
public readonly name = 'poll';
|
public readonly name = 'poll';
|
||||||
|
|
|
@ -10,7 +10,7 @@ import got from 'got';
|
||||||
import * as Reversi from './engine.js';
|
import * as Reversi from './engine.js';
|
||||||
import config from '@/config.js';
|
import config from '@/config.js';
|
||||||
import serifs from '@/serifs.js';
|
import serifs from '@/serifs.js';
|
||||||
import { User } from '@/misskey/user.js';
|
import type { User } from '@/misskey/user.js';
|
||||||
|
|
||||||
function getUserName(user) {
|
function getUserName(user) {
|
||||||
return user.name || user.username;
|
return user.name || user.username;
|
||||||
|
|
Loading…
Reference in a new issue