diff options
| author | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-31 19:55:00 +0900 |
|---|---|---|
| committer | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-31 20:33:14 +0900 |
| commit | 68a9aac9573969311dd00a44536c3ee4c05b883d (patch) | |
| tree | 7d6c502c1e2c61eb3327f678f766f23bda10c1e7 /src/server/api/common/drive/upload_from_url.ts | |
| parent | Store texts as HTML (diff) | |
| download | misskey-68a9aac9573969311dd00a44536c3ee4c05b883d.tar.gz misskey-68a9aac9573969311dd00a44536c3ee4c05b883d.tar.bz2 misskey-68a9aac9573969311dd00a44536c3ee4c05b883d.zip | |
Implement remote status retrieval
Diffstat (limited to 'src/server/api/common/drive/upload_from_url.ts')
| -rw-r--r-- | src/server/api/common/drive/upload_from_url.ts | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/src/server/api/common/drive/upload_from_url.ts b/src/server/api/common/drive/upload_from_url.ts deleted file mode 100644 index b825e4c531..0000000000 --- a/src/server/api/common/drive/upload_from_url.ts +++ /dev/null @@ -1,46 +0,0 @@ -import * as URL from 'url'; -import { IDriveFile, validateFileName } from '../../../../models/drive-file'; -import create from './add-file'; -import * as debug from 'debug'; -import * as tmp from 'tmp'; -import * as fs from 'fs'; -import * as request from 'request'; - -const log = debug('misskey:common:drive:upload_from_url'); - -export default async (url, user, folderId = null): Promise<IDriveFile> => { - let name = URL.parse(url).pathname.split('/').pop(); - if (!validateFileName(name)) { - name = null; - } - - // Create temp file - const path = await new Promise((res: (string) => void, rej) => { - tmp.file((e, path) => { - if (e) return rej(e); - res(path); - }); - }); - - // write content at URL to temp file - await new Promise((res, rej) => { - const writable = fs.createWriteStream(path); - request(url) - .on('error', rej) - .on('end', () => { - writable.close(); - res(path); - }) - .pipe(writable) - .on('error', rej); - }); - - const driveFile = await create(user, path, name, null, folderId); - - // clean-up - fs.unlink(path, (e) => { - if (e) log(e.stack); - }); - - return driveFile; -}; |