Skip to content

Commit

Permalink
v0.0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaina committed Sep 20, 2023
1 parent 0e79a81 commit d87bc5f
Show file tree
Hide file tree
Showing 13 changed files with 621 additions and 533 deletions.
17 changes: 15 additions & 2 deletions README.md
Expand Up @@ -10,6 +10,8 @@ Misskeyの/proxyが単体で動作します(Misskeyのコードがほぼその
一応AWS Lambdaで動かす実装を用意しましたが、全くおすすめしません。
https://github.com/tamaina/media-proxy-lambda

Sharp.jsを使っているため、メモリアロケータにjemallocを指定することをお勧めします。

## Fastifyプラグインとして動作させる
### npm install

Expand All @@ -36,6 +38,13 @@ git clone https://github.com/misskey-dev/media-proxy.git
cd media-proxy
```

### jemallocをインストール
Debian/Ubuntuのaptの場合

```
sudo apt install libjemalloc2
```

### pnpm install
```
NODE_ENV=production pnpm install
Expand Down Expand Up @@ -76,14 +85,17 @@ export default {
適当にサーバーを公開してください。
(ここではmediaproxy.example.comで公開するものとします。)

メモ書き程度にsystemdでの開始方法を残しますが、もしかしたらAWS Lambdaとかで動かしたほうが楽かもしれません
メモ書き程度にsystemdでの開始方法を残します
(サーバーレスだとsharp.jsが動かない可能性が高いため、そこはなんとかしてください)

systemdサービスのファイルを作成…

/etc/systemd/system/misskey-proxy.service

エディタで開き、以下のコードを貼り付けて保存(ユーザーやポートは適宜変更すること):
エディタで開き、以下のコードを貼り付けて保存

ユーザーやポートは適宜変更すること。
また、arm64の場合`Environment="LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"`のx86_64をaarch64に変更する必要がある。jemallocのパスはディストリビューションによって変わる可能性がある。

```systemd
[Unit]
Expand All @@ -94,6 +106,7 @@ Type=simple
User=misskey
ExecStart=/usr/bin/npm start
WorkingDirectory=/home/misskey/media-proxy
Environment="LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2"
Environment="NODE_ENV=production"
Environment="PORT=3000"
TimeoutSec=60
Expand Down
4 changes: 2 additions & 2 deletions built/download.d.ts
@@ -1,5 +1,5 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import * as http from 'node:http';
import * as https from 'node:https';
export type DownloadConfig = {
Expand Down
9 changes: 4 additions & 5 deletions built/download.js
@@ -1,9 +1,8 @@
import * as fs from 'node:fs';
import * as stream from 'node:stream';
import * as util from 'node:util';
import ipaddr from 'ipaddr.js';
import got, * as Got from 'got';
import IPCIDR from 'ip-cidr';
import PrivateIp from 'private-ip';
import { StatusError } from './status-error.js';
import { getAgents } from './http.js';
import { parse } from 'content-disposition';
Expand Down Expand Up @@ -95,11 +94,11 @@ export async function downloadUrl(url, path, settings = defaultDownloadConfig) {
};
}
function isPrivateIp(ip, allowedPrivateNetworks) {
const parsedIp = ipaddr.parse(ip);
for (const net of allowedPrivateNetworks ?? []) {
const cidr = new IPCIDR(net);
if (cidr.contains(ip)) {
if (parsedIp.match(ipaddr.parseCIDR(net))) {
return false;
}
}
return PrivateIp(ip) ?? false;
return parsedIp.range() !== 'unicast';
}
2 changes: 1 addition & 1 deletion built/file-info.js
Expand Up @@ -46,7 +46,7 @@ async function checkSvg(path) {
const size = await getFileSize(path);
if (size > 1 * 1024 * 1024)
return false;
return isSvg(fs.readFileSync(path));
return isSvg(fs.readFileSync(path, { encoding: 'utf-8' }));
}
catch {
return false;
Expand Down
4 changes: 2 additions & 2 deletions built/http.d.ts
@@ -1,5 +1,5 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import * as http from 'node:http';
import * as https from 'node:https';
export declare function getAgents(proxy?: string): {
Expand Down
4 changes: 2 additions & 2 deletions built/image-processor.d.ts
@@ -1,5 +1,5 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import sharp from 'sharp';
import { Readable } from 'node:stream';
export type IImage = {
Expand Down
4 changes: 2 additions & 2 deletions built/index.d.ts
@@ -1,5 +1,5 @@
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" resolution-mode="require"/>
/// <reference types="node" resolution-mode="require"/>
import * as http from 'node:http';
import * as https from 'node:https';
import type { FastifyInstance } from 'fastify';
Expand Down
32 changes: 16 additions & 16 deletions package.json
@@ -1,9 +1,9 @@
{
"name": "misskey-media-proxy",
"version": "0.0.22",
"version": "0.0.23",
"description": "The Media Proxy for Misskey",
"main": "built/index.js",
"packageManager": "pnpm@7.28.0",
"packageManager": "pnpm@8.7.5",
"type": "module",
"files": [
"built",
Expand All @@ -27,26 +27,26 @@
"homepage": "https://github.com/misskey-dev/media-proxy#readme",
"devDependencies": {
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.57",
"@types/content-disposition": "^0.5.5",
"@types/node": "^18.16.7",
"@types/sharp": "^0.31.1",
"@types/tmp": "^0.2.3",
"typescript": "^4.9.5"
"@swc/core": "^1.3.86",
"@types/content-disposition": "^0.5.6",
"@types/node": "^20.6.3",
"@types/tmp": "^0.2.4",
"typescript": "^5.2.2"
},
"dependencies": {
"@fastify/static": "^6.10.1",
"@fastify/static": "^6.11.2",
"cacheable-lookup": "^7.0.0",
"content-disposition": "^0.5.4",
"fastify": "^4.17.0",
"fastify-cli": "^5.7.1",
"file-type": "^18.4.0",
"got": "^12.6.0",
"fastify": "^4.23.2",
"fastify-cli": "^5.8.0",
"file-type": "^18.5.0",
"got": "^13.0.0",
"hpagent": "^1.2.0",
"ip-cidr": "^3.1.0",
"is-svg": "^4.4.0",
"private-ip": "^3.0.0",
"sharp": "^0.31.3",
"ipaddr.js": "^2.1.0",
"is-svg": "^5.0.0",
"private-ip": "^3.0.1",
"sharp": "^0.32.6",
"sharp-read-bmp": "github:misskey-dev/sharp-read-bmp",
"tmp": "^0.2.1"
}
Expand Down

0 comments on commit d87bc5f

Please sign in to comment.