@fedify/cli 1.8.11 → 2.0.0-dev.1757
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +72 -0
- package/dist/cache.js +17 -0
- package/dist/deno.js +72 -0
- package/dist/docloader.js +52 -0
- package/dist/globals.js +49 -0
- package/dist/imagerenderer.js +105 -0
- package/dist/inbox/rendercode.js +57 -0
- package/dist/inbox/view.js +508 -0
- package/dist/inbox.js +315 -0
- package/dist/init/action/configs.js +81 -0
- package/dist/init/action/deps.js +52 -0
- package/dist/init/action/dir.js +16 -0
- package/dist/init/action/env.js +13 -0
- package/dist/init/action/install.js +22 -0
- package/dist/init/action/mod.js +39 -0
- package/dist/init/action/notice.js +62 -0
- package/dist/init/action/patch.js +141 -0
- package/dist/init/action/precommand.js +23 -0
- package/dist/init/action/recommend.js +24 -0
- package/dist/init/action/set.js +31 -0
- package/dist/init/action/templates.js +57 -0
- package/dist/init/action/utils.js +50 -0
- package/dist/init/ask/dir.js +82 -0
- package/dist/init/ask/kv.js +33 -0
- package/dist/init/ask/mod.js +16 -0
- package/dist/init/ask/mq.js +33 -0
- package/dist/init/ask/pm.js +49 -0
- package/dist/init/ask/wf.js +29 -0
- package/dist/init/command.js +25 -0
- package/dist/init/const.js +31 -0
- package/dist/init/json/biome.js +24 -0
- package/dist/init/json/kv.js +53 -0
- package/dist/init/json/mq.js +72 -0
- package/dist/init/json/pm.js +44 -0
- package/dist/init/json/rt.js +39 -0
- package/dist/init/json/vscode-settings-for-deno.js +53 -0
- package/dist/init/json/vscode-settings.js +49 -0
- package/dist/init/lib.js +129 -0
- package/dist/init/mod.js +5 -0
- package/dist/init/webframeworks.js +133 -0
- package/dist/kv.bun.js +17 -0
- package/dist/kv.node.js +17 -0
- package/dist/log.js +52 -0
- package/dist/lookup.js +287 -0
- package/dist/mod.js +34 -0
- package/dist/nodeinfo.js +261 -0
- package/dist/table.js +24 -0
- package/dist/tempserver.js +71 -0
- package/dist/tunnel.js +21 -0
- package/dist/utils.js +67 -0
- package/dist/webfinger/action.js +44 -0
- package/dist/webfinger/command.js +20 -0
- package/dist/webfinger/error.js +47 -0
- package/dist/webfinger/lib.js +45 -0
- package/dist/webfinger/mod.js +5 -0
- package/package.json +64 -24
- package/scripts/pack.ts +64 -0
- package/src/cache.ts +17 -0
- package/src/docloader.ts +67 -0
- package/src/globals.ts +43 -0
- package/src/imagerenderer.ts +149 -0
- package/src/inbox/entry.ts +10 -0
- package/src/inbox/rendercode.ts +68 -0
- package/src/inbox/view.tsx +598 -0
- package/src/inbox.tsx +535 -0
- package/src/init/action/configs.ts +88 -0
- package/src/init/action/deps.ts +93 -0
- package/src/init/action/dir.ts +11 -0
- package/src/init/action/env.ts +14 -0
- package/src/init/action/install.ts +59 -0
- package/src/init/action/mod.ts +66 -0
- package/src/init/action/notice.ts +101 -0
- package/src/init/action/patch.ts +212 -0
- package/src/init/action/precommand.ts +22 -0
- package/src/init/action/recommend.ts +38 -0
- package/src/init/action/set.ts +78 -0
- package/src/init/action/templates.ts +95 -0
- package/src/init/action/utils.ts +64 -0
- package/src/init/ask/dir.ts +98 -0
- package/src/init/ask/kv.ts +39 -0
- package/src/init/ask/mod.ts +23 -0
- package/src/init/ask/mq.ts +37 -0
- package/src/init/ask/pm.ts +58 -0
- package/src/init/ask/wf.ts +27 -0
- package/src/init/command.ts +64 -0
- package/src/init/const.ts +4 -0
- package/src/init/json/biome.json +17 -0
- package/src/init/json/kv.json +39 -0
- package/src/init/json/mq.json +95 -0
- package/src/init/json/pm.json +47 -0
- package/src/init/json/rt.json +42 -0
- package/src/init/json/vscode-settings-for-deno.json +43 -0
- package/src/init/json/vscode-settings.json +41 -0
- package/src/init/lib.ts +220 -0
- package/src/init/mod.ts +2 -0
- package/src/init/templates/defaults/federation.ts.tpl +23 -0
- package/src/init/templates/defaults/logging.ts.tpl +23 -0
- package/src/init/templates/express/app.ts.tpl +16 -0
- package/src/init/templates/express/index.ts.tpl +6 -0
- package/src/init/templates/hono/app.tsx.tpl +14 -0
- package/src/init/templates/hono/index/bun.ts.tpl +10 -0
- package/src/init/templates/hono/index/deno.ts.tpl +13 -0
- package/src/init/templates/hono/index/node.ts.tpl +14 -0
- package/src/init/templates/next/middleware.ts.tpl +45 -0
- package/src/init/templates/nitro/nitro.config.ts.tpl +5 -0
- package/src/init/templates/nitro/server/error.ts.tpl +3 -0
- package/src/init/templates/nitro/server/middleware/federation.ts.tpl +8 -0
- package/src/init/types.ts +88 -0
- package/src/init/webframeworks.ts +151 -0
- package/src/kv.bun.ts +12 -0
- package/src/kv.node.ts +11 -0
- package/src/log.ts +64 -0
- package/src/lookup.test.ts +182 -0
- package/src/lookup.ts +558 -0
- package/src/mod.ts +45 -0
- package/src/nodeinfo.test.ts +229 -0
- package/src/nodeinfo.ts +447 -0
- package/src/table.ts +17 -0
- package/src/tempserver.ts +87 -0
- package/src/tunnel.ts +32 -0
- package/src/utils.ts +136 -0
- package/src/webfinger/action.ts +50 -0
- package/src/webfinger/command.ts +59 -0
- package/src/webfinger/error.ts +47 -0
- package/src/webfinger/lib.ts +37 -0
- package/src/webfinger/mod.test.ts +79 -0
- package/src/webfinger/mod.ts +2 -0
- package/tsdown.config.ts +24 -0
- package/src/install.mjs +0 -189
- package/src/run.mjs +0 -22
package/deno.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fedify/cli",
|
|
3
|
+
"version": "2.0.0-dev.1757+5037a70f",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": "./src/mod.ts",
|
|
6
|
+
"imports": {
|
|
7
|
+
"@david/dax": "jsr:@david/dax@^0.43.2",
|
|
8
|
+
"@fxts/core": "npm:@fxts/core@^1.15.0",
|
|
9
|
+
"@hongminhee/localtunnel": "jsr:@hongminhee/localtunnel@^0.3.0",
|
|
10
|
+
"@inquirer/prompts": "npm:@inquirer/prompts@^7.8.4",
|
|
11
|
+
"@jimp/core": "npm:@jimp/core@^1.6.0",
|
|
12
|
+
"@jimp/wasm-webp": "npm:@jimp/wasm-webp@^1.6.0",
|
|
13
|
+
"@optique/core": "jsr:@optique/core@^0.6.1",
|
|
14
|
+
"@optique/run": "jsr:@optique/run@^0.6.1",
|
|
15
|
+
"@poppanator/http-constants": "npm:@poppanator/http-constants@^1.1.1",
|
|
16
|
+
"chalk": "npm:chalk@^5.6.2",
|
|
17
|
+
"cli-table3": "npm:cli-table3@^0.6.5",
|
|
18
|
+
"env-paths": "npm:env-paths@^3.0.0",
|
|
19
|
+
"fetch-mock": "npm:fetch-mock@^12.5.4",
|
|
20
|
+
"hono": "jsr:@hono/hono@^4.8.3",
|
|
21
|
+
"icojs": "npm:icojs@^0.19.5",
|
|
22
|
+
"inquirer-toggle": "npm:inquirer-toggle@^1.0.1",
|
|
23
|
+
"ora": "npm:ora@^8.2.0",
|
|
24
|
+
"shiki": "npm:shiki@^1.6.4",
|
|
25
|
+
"srvx": "npm:srvx@^0.8.7",
|
|
26
|
+
"#kv": "./src/kv.node.ts"
|
|
27
|
+
},
|
|
28
|
+
"exclude": [
|
|
29
|
+
"dist/",
|
|
30
|
+
"fedify-cli-*.tar.xz",
|
|
31
|
+
"fedify-cli-*.tgz",
|
|
32
|
+
"fedify-cli-*.zip"
|
|
33
|
+
],
|
|
34
|
+
"tasks": {
|
|
35
|
+
"codegen": "deno task -f @fedify/fedify codegen",
|
|
36
|
+
"check": {
|
|
37
|
+
"command": "deno task codegen && deno fmt --check && deno lint && deno check src/**/*.ts",
|
|
38
|
+
"dependencies": [
|
|
39
|
+
"codegen"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"run": {
|
|
43
|
+
"command": "deno run --allow-all src/mod.ts",
|
|
44
|
+
"dependencies": [
|
|
45
|
+
"codegen"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"runi": "deno run --allow-all src/mod.ts",
|
|
49
|
+
"pack": {
|
|
50
|
+
"command": "deno run -A scripts/pack.ts",
|
|
51
|
+
"dependencies": [
|
|
52
|
+
"codegen"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"test": {
|
|
56
|
+
"command": "deno test --allow-all",
|
|
57
|
+
"dependencies": [
|
|
58
|
+
"codegen"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"fmt": {
|
|
63
|
+
"exclude": [
|
|
64
|
+
"src/init/templates/**"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"lint": {
|
|
68
|
+
"exclude": [
|
|
69
|
+
"src/init/templates/**"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import envPaths from "env-paths";
|
|
5
|
+
import { mkdir } from "node:fs/promises";
|
|
6
|
+
|
|
7
|
+
//#region src/cache.ts
|
|
8
|
+
const paths = envPaths("fedify", { suffix: "" });
|
|
9
|
+
const DEFAULT_CACHE_DIR = paths.cache;
|
|
10
|
+
let currentCacheDir = DEFAULT_CACHE_DIR;
|
|
11
|
+
async function getCacheDir() {
|
|
12
|
+
await mkdir(currentCacheDir, { recursive: true });
|
|
13
|
+
return currentCacheDir;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getCacheDir };
|
package/dist/deno.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
//#region deno.json
|
|
5
|
+
var name = "@fedify/cli";
|
|
6
|
+
var version = "2.0.0-dev.1757+5037a70f";
|
|
7
|
+
var license = "MIT";
|
|
8
|
+
var exports = "./src/mod.ts";
|
|
9
|
+
var imports = {
|
|
10
|
+
"@david/dax": "jsr:@david/dax@^0.43.2",
|
|
11
|
+
"@fxts/core": "npm:@fxts/core@^1.15.0",
|
|
12
|
+
"@hongminhee/localtunnel": "jsr:@hongminhee/localtunnel@^0.3.0",
|
|
13
|
+
"@inquirer/prompts": "npm:@inquirer/prompts@^7.8.4",
|
|
14
|
+
"@jimp/core": "npm:@jimp/core@^1.6.0",
|
|
15
|
+
"@jimp/wasm-webp": "npm:@jimp/wasm-webp@^1.6.0",
|
|
16
|
+
"@optique/core": "jsr:@optique/core@^0.6.1",
|
|
17
|
+
"@optique/run": "jsr:@optique/run@^0.6.1",
|
|
18
|
+
"@poppanator/http-constants": "npm:@poppanator/http-constants@^1.1.1",
|
|
19
|
+
"chalk": "npm:chalk@^5.6.2",
|
|
20
|
+
"cli-table3": "npm:cli-table3@^0.6.5",
|
|
21
|
+
"env-paths": "npm:env-paths@^3.0.0",
|
|
22
|
+
"fetch-mock": "npm:fetch-mock@^12.5.4",
|
|
23
|
+
"hono": "jsr:@hono/hono@^4.8.3",
|
|
24
|
+
"icojs": "npm:icojs@^0.19.5",
|
|
25
|
+
"inquirer-toggle": "npm:inquirer-toggle@^1.0.1",
|
|
26
|
+
"ora": "npm:ora@^8.2.0",
|
|
27
|
+
"shiki": "npm:shiki@^1.6.4",
|
|
28
|
+
"srvx": "npm:srvx@^0.8.7",
|
|
29
|
+
"#kv": "./src/kv.node.ts"
|
|
30
|
+
};
|
|
31
|
+
var exclude = [
|
|
32
|
+
"dist/",
|
|
33
|
+
"fedify-cli-*.tar.xz",
|
|
34
|
+
"fedify-cli-*.tgz",
|
|
35
|
+
"fedify-cli-*.zip"
|
|
36
|
+
];
|
|
37
|
+
var tasks = {
|
|
38
|
+
"codegen": "deno task -f @fedify/fedify codegen",
|
|
39
|
+
"check": {
|
|
40
|
+
"command": "deno task codegen && deno fmt --check && deno lint && deno check src/**/*.ts",
|
|
41
|
+
"dependencies": ["codegen"]
|
|
42
|
+
},
|
|
43
|
+
"run": {
|
|
44
|
+
"command": "deno run --allow-all src/mod.ts",
|
|
45
|
+
"dependencies": ["codegen"]
|
|
46
|
+
},
|
|
47
|
+
"runi": "deno run --allow-all src/mod.ts",
|
|
48
|
+
"pack": {
|
|
49
|
+
"command": "deno run -A scripts/pack.ts",
|
|
50
|
+
"dependencies": ["codegen"]
|
|
51
|
+
},
|
|
52
|
+
"test": {
|
|
53
|
+
"command": "deno test --allow-all",
|
|
54
|
+
"dependencies": ["codegen"]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var fmt = { "exclude": ["src/init/templates/**"] };
|
|
58
|
+
var lint = { "exclude": ["src/init/templates/**"] };
|
|
59
|
+
var deno_default = {
|
|
60
|
+
name,
|
|
61
|
+
version,
|
|
62
|
+
license,
|
|
63
|
+
exports,
|
|
64
|
+
imports,
|
|
65
|
+
exclude,
|
|
66
|
+
tasks,
|
|
67
|
+
fmt,
|
|
68
|
+
lint
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { deno_default as default };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { kvCache } from "@fedify/fedify";
|
|
5
|
+
import { getDocumentLoader } from "@fedify/vocab-runtime";
|
|
6
|
+
import { getKvStore } from "#kv";
|
|
7
|
+
|
|
8
|
+
//#region src/docloader.ts
|
|
9
|
+
const documentLoaders = {};
|
|
10
|
+
async function getDocumentLoader$1({ userAgent } = {}) {
|
|
11
|
+
if (documentLoaders[userAgent ?? ""]) return documentLoaders[userAgent ?? ""];
|
|
12
|
+
const kv = await getKvStore();
|
|
13
|
+
return documentLoaders[userAgent ?? ""] = kvCache({
|
|
14
|
+
kv,
|
|
15
|
+
rules: [
|
|
16
|
+
[new URLPattern({
|
|
17
|
+
protocol: "http{s}?",
|
|
18
|
+
hostname: "localhost",
|
|
19
|
+
port: "*",
|
|
20
|
+
pathname: "/*",
|
|
21
|
+
search: "*",
|
|
22
|
+
hash: "*"
|
|
23
|
+
}), { seconds: 0 }],
|
|
24
|
+
[new URLPattern({
|
|
25
|
+
protocol: "http{s}?",
|
|
26
|
+
hostname: "127.0.0.1",
|
|
27
|
+
port: "*",
|
|
28
|
+
pathname: "/*",
|
|
29
|
+
search: "*",
|
|
30
|
+
hash: "*"
|
|
31
|
+
}), { seconds: 0 }],
|
|
32
|
+
[new URLPattern({
|
|
33
|
+
protocol: "http{s}?",
|
|
34
|
+
hostname: "\\[\\:\\:1\\]",
|
|
35
|
+
port: "*",
|
|
36
|
+
pathname: "/*",
|
|
37
|
+
search: "*",
|
|
38
|
+
hash: "*"
|
|
39
|
+
}), { seconds: 0 }]
|
|
40
|
+
],
|
|
41
|
+
loader: getDocumentLoader({
|
|
42
|
+
allowPrivateAddress: true,
|
|
43
|
+
userAgent
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function getContextLoader(options = {}) {
|
|
48
|
+
return getDocumentLoader$1(options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { getContextLoader, getDocumentLoader$1 as getDocumentLoader };
|
package/dist/globals.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { recordingSink } from "./log.js";
|
|
5
|
+
import { message, object, option } from "@optique/core";
|
|
6
|
+
import { configure, getConsoleSink } from "@logtape/logtape";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { getFileSink } from "@logtape/file";
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
+
|
|
11
|
+
//#region src/globals.ts
|
|
12
|
+
const debugOption = object("Global options", { debug: option("-d", "--debug", { description: message`Enable debug mode.` }) });
|
|
13
|
+
async function configureLogging() {
|
|
14
|
+
const logFile = process.env["FEDIFY_LOG_FILE"];
|
|
15
|
+
await configure({
|
|
16
|
+
sinks: {
|
|
17
|
+
console: getConsoleSink(),
|
|
18
|
+
recording: recordingSink,
|
|
19
|
+
file: logFile == null ? () => void 0 : getFileSink(logFile)
|
|
20
|
+
},
|
|
21
|
+
filters: {},
|
|
22
|
+
loggers: [
|
|
23
|
+
{
|
|
24
|
+
category: "fedify",
|
|
25
|
+
lowestLevel: "debug",
|
|
26
|
+
sinks: [
|
|
27
|
+
"console",
|
|
28
|
+
"recording",
|
|
29
|
+
"file"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
category: "localtunnel",
|
|
34
|
+
lowestLevel: "debug",
|
|
35
|
+
sinks: ["console", "file"]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
category: ["logtape", "meta"],
|
|
39
|
+
lowestLevel: "warning",
|
|
40
|
+
sinks: ["console", "file"]
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
reset: true,
|
|
44
|
+
contextLocalStorage: new AsyncLocalStorage()
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { configureLogging, debugOption };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { Jimp } from "./nodeinfo.js";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { encodeBase64 } from "byte-encodings/base64";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
|
|
11
|
+
//#region src/imagerenderer.ts
|
|
12
|
+
const KITTY_IDENTIFIERS = [
|
|
13
|
+
"kitty",
|
|
14
|
+
"wezterm",
|
|
15
|
+
"konsole",
|
|
16
|
+
"warp",
|
|
17
|
+
"wayst",
|
|
18
|
+
"st",
|
|
19
|
+
"ghostty"
|
|
20
|
+
];
|
|
21
|
+
function detectTerminalCapabilities() {
|
|
22
|
+
const termProgram = (process.env.TERM_PROGRAM || "").toLowerCase();
|
|
23
|
+
if (KITTY_IDENTIFIERS.includes(termProgram)) return "kitty";
|
|
24
|
+
if (termProgram === "iterm.app") return "iterm2";
|
|
25
|
+
return "none";
|
|
26
|
+
}
|
|
27
|
+
function serializeGrCommand(cmd, payload) {
|
|
28
|
+
const cmdString = Object.entries(cmd).map(([k, v]) => `${k}=${v}`).join(",");
|
|
29
|
+
const encoder = new TextEncoder();
|
|
30
|
+
const parts = [];
|
|
31
|
+
parts.push(encoder.encode("\x1B_G"));
|
|
32
|
+
parts.push(encoder.encode(cmdString));
|
|
33
|
+
if (payload) {
|
|
34
|
+
parts.push(encoder.encode(";"));
|
|
35
|
+
parts.push(encoder.encode(payload));
|
|
36
|
+
}
|
|
37
|
+
parts.push(encoder.encode("\x1B\\"));
|
|
38
|
+
const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
|
|
39
|
+
const result = new Uint8Array(totalLength);
|
|
40
|
+
let offset = 0;
|
|
41
|
+
for (const part of parts) {
|
|
42
|
+
result.set(part, offset);
|
|
43
|
+
offset += part.length;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
async function renderImageKitty(imagePath, cmd) {
|
|
48
|
+
const imageData = await fs.readFile(imagePath);
|
|
49
|
+
const base64Data = encodeBase64(imageData);
|
|
50
|
+
let remaining = base64Data;
|
|
51
|
+
let isFirst = true;
|
|
52
|
+
while (remaining.length > 0) {
|
|
53
|
+
const chunk = remaining.slice(0, 4096);
|
|
54
|
+
remaining = remaining.slice(4096);
|
|
55
|
+
const chunkCmd = {
|
|
56
|
+
...isFirst ? cmd : {},
|
|
57
|
+
m: remaining.length > 0 ? 1 : 0
|
|
58
|
+
};
|
|
59
|
+
const command = serializeGrCommand(chunkCmd, chunk);
|
|
60
|
+
process.stderr.write(command);
|
|
61
|
+
isFirst = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function renderImageITerm2(imagePath) {
|
|
65
|
+
const imageData = await fs.readFile(imagePath);
|
|
66
|
+
const base64Data = encodeBase64(imageData);
|
|
67
|
+
const encoder = new TextEncoder();
|
|
68
|
+
const command = encoder.encode(`\x1b]1337;File=inline=1preserveAspectRatio=1:${base64Data}\x07\n`);
|
|
69
|
+
process.stderr.write(command);
|
|
70
|
+
}
|
|
71
|
+
async function downloadImage(url) {
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch(url);
|
|
74
|
+
const imageData = new Uint8Array(await response.arrayBuffer());
|
|
75
|
+
const extension = new URL(url).pathname.split(".").pop() || "jpg";
|
|
76
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "fedify"));
|
|
77
|
+
const tempPath = path.join(tempDir, `image.${extension}`);
|
|
78
|
+
await fs.writeFile(tempPath, imageData);
|
|
79
|
+
return tempPath;
|
|
80
|
+
} catch (_error) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function renderImages(imageUrls) {
|
|
85
|
+
const graphicsProtocol = detectTerminalCapabilities();
|
|
86
|
+
for (const url of imageUrls) {
|
|
87
|
+
const tempPath = await downloadImage(url.href);
|
|
88
|
+
if (!tempPath) continue;
|
|
89
|
+
const convertedImagePath = `${tempPath}.converted.png`;
|
|
90
|
+
const image = await Jimp.read(tempPath);
|
|
91
|
+
await image.write(convertedImagePath);
|
|
92
|
+
await fs.rm(tempPath);
|
|
93
|
+
console.error();
|
|
94
|
+
if (graphicsProtocol === "kitty") await renderImageKitty(convertedImagePath, {
|
|
95
|
+
a: "T",
|
|
96
|
+
f: 100
|
|
97
|
+
});
|
|
98
|
+
else if (graphicsProtocol === "iterm2") await renderImageITerm2(convertedImagePath);
|
|
99
|
+
else continue;
|
|
100
|
+
console.error();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { renderImages };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
|
|
4
|
+
import { getContextLoader } from "../docloader.js";
|
|
5
|
+
import { getStatusText } from "@poppanator/http-constants";
|
|
6
|
+
|
|
7
|
+
//#region src/inbox/rendercode.ts
|
|
8
|
+
async function renderRequest(request) {
|
|
9
|
+
request = request.clone();
|
|
10
|
+
const url = new URL(request.url);
|
|
11
|
+
let code = `${request.method} ${url.pathname + url.search}\n`;
|
|
12
|
+
for (const [key, value] of request.headers.entries()) code += `${capitalize(key)}: ${value}\n`;
|
|
13
|
+
let body;
|
|
14
|
+
try {
|
|
15
|
+
body = await request.text();
|
|
16
|
+
} catch (_) {
|
|
17
|
+
body = "[Failed to decode body; it may be binary.]";
|
|
18
|
+
}
|
|
19
|
+
code += `\n${body}`;
|
|
20
|
+
return code;
|
|
21
|
+
}
|
|
22
|
+
async function renderResponse(response) {
|
|
23
|
+
response = response.clone();
|
|
24
|
+
let code = `${response.status} ${response.statusText === "" ? getStatusText(response.status) : response.statusText}\n`;
|
|
25
|
+
for (const [key, value] of response.headers.entries()) code += `${capitalize(key)}: ${value}\n`;
|
|
26
|
+
let body;
|
|
27
|
+
try {
|
|
28
|
+
body = await response.text();
|
|
29
|
+
} catch (_) {
|
|
30
|
+
body = "[Failed to decode body; it may be binary.]";
|
|
31
|
+
}
|
|
32
|
+
code += `\n${body}`;
|
|
33
|
+
return code;
|
|
34
|
+
}
|
|
35
|
+
async function renderRawActivity(request) {
|
|
36
|
+
request = request.clone();
|
|
37
|
+
try {
|
|
38
|
+
const activity = await request.json();
|
|
39
|
+
return JSON.stringify(activity, null, 2);
|
|
40
|
+
} catch {
|
|
41
|
+
return "[Failed to decode body; it may not be JSON.]";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function renderActivity(activity, expand = false) {
|
|
45
|
+
const contextLoader = await getContextLoader();
|
|
46
|
+
const jsonLd = await activity.toJsonLd({
|
|
47
|
+
contextLoader,
|
|
48
|
+
format: expand ? "expand" : "compact"
|
|
49
|
+
});
|
|
50
|
+
return JSON.stringify(jsonLd, null, 2);
|
|
51
|
+
}
|
|
52
|
+
function capitalize(name) {
|
|
53
|
+
return name.replace(/(^|-)./g, (match) => match.toUpperCase());
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { renderActivity, renderRawActivity, renderRequest, renderResponse };
|