mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 16:33:09 +02:00
Add User-Agent header (#2602)
This commit is contained in:
parent
921609cab1
commit
5b039a1bee
5 changed files with 12 additions and 2 deletions
|
@ -7,6 +7,7 @@ import { URL } from 'url';
|
||||||
import * as yaml from 'js-yaml';
|
import * as yaml from 'js-yaml';
|
||||||
import { Source, Mixin } from './types';
|
import { Source, Mixin } from './types';
|
||||||
import isUrl = require('is-url');
|
import isUrl = require('is-url');
|
||||||
|
const pkg = require('../../package.json');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path of configuration directory
|
* Path of configuration directory
|
||||||
|
@ -43,6 +44,7 @@ export default function load() {
|
||||||
mixin.stats_url = `${mixin.scheme}://${mixin.host}/stats`;
|
mixin.stats_url = `${mixin.scheme}://${mixin.host}/stats`;
|
||||||
mixin.status_url = `${mixin.scheme}://${mixin.host}/status`;
|
mixin.status_url = `${mixin.scheme}://${mixin.host}/status`;
|
||||||
mixin.drive_url = `${mixin.scheme}://${mixin.host}/files`;
|
mixin.drive_url = `${mixin.scheme}://${mixin.host}/files`;
|
||||||
|
mixin.user_agent = `Misskey/${pkg.version} (${config.url})`;
|
||||||
|
|
||||||
if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256;
|
if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256;
|
||||||
if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8;
|
if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8;
|
||||||
|
|
|
@ -114,6 +114,7 @@ export type Mixin = {
|
||||||
status_url: string;
|
status_url: string;
|
||||||
dev_url: string;
|
dev_url: string;
|
||||||
drive_url: string;
|
drive_url: string;
|
||||||
|
user_agent: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Config = Source & Mixin;
|
export type Config = Source & Mixin;
|
||||||
|
|
|
@ -27,6 +27,7 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: pathname + search,
|
path: pathname + search,
|
||||||
headers: {
|
headers: {
|
||||||
|
'User-Agent': config.user_agent,
|
||||||
'Content-Type': 'application/activity+json',
|
'Content-Type': 'application/activity+json',
|
||||||
'Digest': `SHA-256=${hash}`
|
'Digest': `SHA-256=${hash}`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import * as request from 'request-promise-native';
|
import * as request from 'request-promise-native';
|
||||||
import * as debug from 'debug';
|
import * as debug from 'debug';
|
||||||
import { IObject } from './type';
|
import { IObject } from './type';
|
||||||
//import config from '../../config';
|
import config from '../../config';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub:resolver');
|
const log = debug('misskey:activitypub:resolver');
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ export default class Resolver {
|
||||||
const object = await request({
|
const object = await request({
|
||||||
url: value,
|
url: value,
|
||||||
headers: {
|
headers: {
|
||||||
|
'User-Agent': config.user_agent,
|
||||||
Accept: 'application/activity+json, application/ld+json'
|
Accept: 'application/activity+json, application/ld+json'
|
||||||
},
|
},
|
||||||
json: true
|
json: true
|
||||||
|
|
|
@ -34,7 +34,12 @@ export default async (url: string, user: IUser, folderId: mongodb.ObjectID = nul
|
||||||
// write content at URL to temp file
|
// write content at URL to temp file
|
||||||
await new Promise((res, rej) => {
|
await new Promise((res, rej) => {
|
||||||
const writable = fs.createWriteStream(path);
|
const writable = fs.createWriteStream(path);
|
||||||
request(url)
|
request({
|
||||||
|
url,
|
||||||
|
headers: {
|
||||||
|
'User-Agent': config.user_agent
|
||||||
|
}
|
||||||
|
})
|
||||||
.on('error', rej)
|
.on('error', rej)
|
||||||
.on('end', () => {
|
.on('end', () => {
|
||||||
writable.close();
|
writable.close();
|
||||||
|
|
Loading…
Reference in a new issue