Skip to content

Commit

Permalink
fix(upload): ファイルのアップロードができるように (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
u1-liquid committed Jan 24, 2024
1 parent ff86ef2 commit 1aa59c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/ws": "8.5.10",
"canvas": "2.11.2",
"chalk": "5.3.0",
"formdata-node": "6.0.3",
"got": "14.0.0",
"lokijs": "1.5.12",
"memory-streams": "0.1.3",
Expand All @@ -28,7 +29,6 @@
"promise-retry": "2.0.1",
"random-seed": "0.3.0",
"reconnecting-websocket": "4.4.0",
"request": "2.88.2",
"seedrandom": "3.0.5",
"ts-patch": "3.1.2",
"twemoji-parser": "14.0.0",
Expand Down
15 changes: 7 additions & 8 deletions src/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from 'fs';
import { bindThis } from '@/decorators.js';
import loki from 'lokijs';
import got from 'got';
import { FormData, File } from 'formdata-node';
import chalk from 'chalk';
import { v4 as uuid } from 'uuid';

Expand Down Expand Up @@ -343,16 +344,14 @@ export default class 藍 {
* ファイルをドライブにアップロードします
*/
@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({
url: `${config.apiUrl}/drive/files/create`,
form: {
i: config.i,
file: {
value: file,
options: meta
}
},
body: form,
json: true
}).json();
return res;
Expand Down

0 comments on commit 1aa59c5

Please sign in to comment.