mirror of
https://github.com/paricafe/misskey.git
synced 2024-12-01 04:06:44 -06:00
Use proxy instead of weserv for url-preview images (#4466)
This commit is contained in:
parent
c6cdfa2f5a
commit
4d425fc8a4
2 changed files with 9 additions and 2 deletions
|
@ -6,7 +6,7 @@ import * as request from 'request';
|
||||||
import fileType from 'file-type';
|
import fileType from 'file-type';
|
||||||
import { serverLogger } from '..';
|
import { serverLogger } from '..';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import { IImage, ConvertToPng } from '../../services/drive/image-processor';
|
import { IImage, ConvertToPng, ConvertToJpeg } from '../../services/drive/image-processor';
|
||||||
import checkSvg from '../../misc/check-svg';
|
import checkSvg from '../../misc/check-svg';
|
||||||
|
|
||||||
export async function proxyMedia(ctx: Koa.BaseContext) {
|
export async function proxyMedia(ctx: Koa.BaseContext) {
|
||||||
|
@ -29,6 +29,8 @@ export async function proxyMedia(ctx: Koa.BaseContext) {
|
||||||
|
|
||||||
if ('static' in ctx.query && ['image/png', 'image/gif'].includes(type)) {
|
if ('static' in ctx.query && ['image/png', 'image/gif'].includes(type)) {
|
||||||
image = await ConvertToPng(path, 498, 280);
|
image = await ConvertToPng(path, 498, 280);
|
||||||
|
} else if ('preview' in ctx.query && ['image/jpeg', 'image/png', 'image/gif'].includes(type)) {
|
||||||
|
image = await ConvertToJpeg(path, 200, 200);
|
||||||
} else {
|
} else {
|
||||||
image = {
|
image = {
|
||||||
data: fs.readFileSync(path),
|
data: fs.readFileSync(path),
|
||||||
|
|
|
@ -3,6 +3,8 @@ import * as request from 'request-promise-native';
|
||||||
import summaly from 'summaly';
|
import summaly from 'summaly';
|
||||||
import fetchMeta from '../../misc/fetch-meta';
|
import fetchMeta from '../../misc/fetch-meta';
|
||||||
import Logger from '../../services/logger';
|
import Logger from '../../services/logger';
|
||||||
|
import config from '../../config';
|
||||||
|
import { query } from '../../prelude/url';
|
||||||
|
|
||||||
const logger = new Logger('url-preview');
|
const logger = new Logger('url-preview');
|
||||||
|
|
||||||
|
@ -44,7 +46,10 @@ module.exports = async (ctx: Koa.BaseContext) => {
|
||||||
function wrap(url: string): string {
|
function wrap(url: string): string {
|
||||||
return url != null
|
return url != null
|
||||||
? url.match(/^https?:\/\//)
|
? url.match(/^https?:\/\//)
|
||||||
? `https://images.weserv.nl/?url=${encodeURIComponent(url.replace(/^http:\/\//, '').replace(/^https:\/\//, 'ssl:'))}&w=200&h=200`
|
? `${config.url}/proxy/preview.jpg?${query({
|
||||||
|
url,
|
||||||
|
preview: '1'
|
||||||
|
})}`
|
||||||
: url
|
: url
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue