mirror of
https://github.com/misskey-dev/media-proxy.git
synced 2025-04-29 02:47:26 +09:00
No longer returns 403 if the file is not an image.
This commit is contained in:
parent
39908281a1
commit
28ac7a4341
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Misskeyの/proxyが単体で動作します(Misskeyのコードがほぼそのまま移植されています)。
|
Misskeyの/proxyが単体で動作します(Misskeyのコードがほぼそのまま移植されています)。
|
||||||
|
|
||||||
|
/proxyは画像ではないと403を返しますが、Media Proxyではそのまま内容を送信します。
|
||||||
|
|
||||||
**Fastifyプラグインとして動作する気がします。**
|
**Fastifyプラグインとして動作する気がします。**
|
||||||
`pnpm start`は[fastify-cli](https://github.com/fastify/fastify-cli)が動作します。
|
`pnpm start`は[fastify-cli](https://github.com/fastify/fastify-cli)が動作します。
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ export default {
|
|||||||
// プライベートネットワークでも許可するIP CIDR(default.ymlと同じ)
|
// プライベートネットワークでも許可するIP CIDR(default.ymlと同じ)
|
||||||
allowedPrivateNetworks: [],
|
allowedPrivateNetworks: [],
|
||||||
|
|
||||||
// ダウンロードするファイルの最大サイズ
|
// ダウンロードするファイルの最大サイズ (bytes)
|
||||||
maxSize: 262144000,
|
maxSize: 262144000,
|
||||||
|
|
||||||
// フォワードプロキシ
|
// フォワードプロキシ
|
||||||
|
@ -3,7 +3,6 @@ import { fileURLToPath } from 'node:url';
|
|||||||
import { dirname } from 'node:path';
|
import { dirname } from 'node:path';
|
||||||
import fastifyStatic from '@fastify/static';
|
import fastifyStatic from '@fastify/static';
|
||||||
import { createTemp } from './create-temp.js';
|
import { createTemp } from './create-temp.js';
|
||||||
import { FILE_TYPE_BROWSERSAFE } from './const.js';
|
|
||||||
import { convertToWebpStream, webpDefault } from './image-processor.js';
|
import { convertToWebpStream, webpDefault } from './image-processor.js';
|
||||||
import { detectType, isMimeImage } from './file-info.js';
|
import { detectType, isMimeImage } from './file-info.js';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
@ -143,9 +142,6 @@ async function proxyHandler(request, reply) {
|
|||||||
else if (file.mime === 'image/svg+xml') {
|
else if (file.mime === 'image/svg+xml') {
|
||||||
image = convertToWebpStream(file.path, 2048, 2048);
|
image = convertToWebpStream(file.path, 2048, 2048);
|
||||||
}
|
}
|
||||||
else if (!file.mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(file.mime)) {
|
|
||||||
throw new StatusError('Rejected type', 403, 'Rejected type');
|
|
||||||
}
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
image = {
|
image = {
|
||||||
data: fs.createReadStream(file.path),
|
data: fs.createReadStream(file.path),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey-media-proxy",
|
"name": "misskey-media-proxy",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"description": "The Media Proxy for Misskey",
|
"description": "The Media Proxy for Misskey",
|
||||||
"main": "built/index.js",
|
"main": "built/index.js",
|
||||||
"packageManager": "pnpm@7.26.0",
|
"packageManager": "pnpm@7.26.0",
|
||||||
|
@ -93,7 +93,6 @@ export async function downloadUrl(url: string, path: string, settings:DownloadCo
|
|||||||
if (process.env.NODE_ENV !== 'production') console.log(`Download finished: ${url}`);
|
if (process.env.NODE_ENV !== 'production') console.log(`Download finished: ${url}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function isPrivateIp(ip: string, allowedPrivateNetworks: string[]): boolean {
|
function isPrivateIp(ip: string, allowedPrivateNetworks: string[]): boolean {
|
||||||
for (const net of allowedPrivateNetworks ?? []) {
|
for (const net of allowedPrivateNetworks ?? []) {
|
||||||
const cidr = new IPCIDR(net);
|
const cidr = new IPCIDR(net);
|
||||||
|
@ -182,8 +182,6 @@ async function proxyHandler(request: FastifyRequest<{ Params: { url: string; };
|
|||||||
};
|
};
|
||||||
} else if (file.mime === 'image/svg+xml') {
|
} else if (file.mime === 'image/svg+xml') {
|
||||||
image = convertToWebpStream(file.path, 2048, 2048);
|
image = convertToWebpStream(file.path, 2048, 2048);
|
||||||
} else if (!file.mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(file.mime)) {
|
|
||||||
throw new StatusError('Rejected type', 403, 'Rejected type');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user