This commit is contained in:
syuilo 2018-04-05 18:08:51 +09:00
parent f5c55d46b7
commit 06347cd71e
4 changed files with 22 additions and 8 deletions

View File

@ -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);

View File

@ -30,6 +30,10 @@ const ev = new Xev();
process.title = 'Misskey';
if (process.env.NODE_ENV != 'production') {
process.env.DEBUG = 'misskey:*';
}
// https://github.com/Automattic/kue/issues/822
require('events').EventEmitter.prototype._maxListeners = 256;

View File

@ -31,7 +31,7 @@ export default async (value, verifier?: string) => {
const user = await User.insert({
avatarId: null,
bannerId: null,
createdAt: Date.parse(object.published),
createdAt: Date.parse(object.published) || null,
description: summaryDOM.textContent,
followersCount: 0,
followingCount: 0,
@ -55,14 +55,14 @@ export default async (value, verifier?: string) => {
const [avatarId, bannerId] = await Promise.all([
object.icon,
object.image
].map(async url => {
if (url === undefined) {
].map(async img => {
if (img === undefined) {
return null;
}
const img = await uploadFromUrl(url, user);
const file = await uploadFromUrl(img.url, user);
return img._id;
return file._id;
}));
User.update({ _id: user._id }, { $set: { avatarId, bannerId } });

View File

@ -1,6 +1,8 @@
import { IObject } from "./type";
import * as request from 'request-promise-native';
import * as debug from 'debug';
import { IObject } from './type';
const request = require('request-promise-native');
const log = debug('misskey:activitypub:resolver');
export default class Resolver {
private history: Set<string>;
@ -57,6 +59,8 @@ export default class Resolver {
throw new Error('invalid response');
}
log(`resolved: ${JSON.stringify(object)}`);
return object;
}
}