wip
This commit is contained in:
parent
f5c55d46b7
commit
06347cd71e
4 changed files with 22 additions and 8 deletions
|
|
@ -6,14 +6,18 @@ import * as tmp from 'tmp';
|
|||
import * as fs from 'fs';
|
||||
import * as request from 'request';
|
||||
|
||||
const log = debug('misskey:common:drive:upload_from_url');
|
||||
const log = debug('misskey:drive:upload-from-url');
|
||||
|
||||
export default async (url, user, folderId = null, uri = null): Promise<IDriveFile> => {
|
||||
log(`REQUESTED: ${url}`);
|
||||
|
||||
let name = URL.parse(url).pathname.split('/').pop();
|
||||
if (!validateFileName(name)) {
|
||||
name = null;
|
||||
}
|
||||
|
||||
log(`name: ${name}`);
|
||||
|
||||
// Create temp file
|
||||
const path = await new Promise((res: (string) => void, rej) => {
|
||||
tmp.file((e, path) => {
|
||||
|
|
@ -37,6 +41,8 @@ export default async (url, user, folderId = null, uri = null): Promise<IDriveFil
|
|||
|
||||
const driveFile = await create(user, path, name, null, folderId, false, uri);
|
||||
|
||||
log(`created: ${driveFile._id}`);
|
||||
|
||||
// clean-up
|
||||
fs.unlink(path, (e) => {
|
||||
if (e) log(e.stack);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue