@syncshio/kano-plugin-civitai 0.0.0-stage → 2.0.0
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.
Potentially problematic release.
This version of @syncshio/kano-plugin-civitai might be problematic. Click here for more details.
- package/dist/entry.js +227 -0
- package/kano-release.json +5 -0
- package/package.json +25 -4
- package/plugin.json +23 -0
- package/README.md +0 -3
package/dist/entry.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
//#region ../kano-plugin-sdk/src/helpers/define-plugin.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e;
|
|
4
|
+
}
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region packages/plugins/civitai/provider.ts
|
|
7
|
+
var t = "https://civitai.com", n = `${t}/api/v1`, r = {
|
|
8
|
+
checkpoint: "Checkpoint",
|
|
9
|
+
lora: "LORA",
|
|
10
|
+
lycoris: "LoCon",
|
|
11
|
+
vae: "VAE",
|
|
12
|
+
embedding: "TextualInversion",
|
|
13
|
+
hypernetwork: "Hypernetwork",
|
|
14
|
+
controlnet: "Controlnet",
|
|
15
|
+
upscaler: "Upscaler"
|
|
16
|
+
};
|
|
17
|
+
function i(e) {
|
|
18
|
+
return e && typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
19
|
+
}
|
|
20
|
+
function a(e) {
|
|
21
|
+
return Array.isArray(e) ? e : [];
|
|
22
|
+
}
|
|
23
|
+
function o(e) {
|
|
24
|
+
return typeof e == "string" ? e : "";
|
|
25
|
+
}
|
|
26
|
+
function s(e) {
|
|
27
|
+
return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : 0;
|
|
28
|
+
}
|
|
29
|
+
function c(e) {
|
|
30
|
+
let t = typeof e == "number" ? String(e) : o(e);
|
|
31
|
+
if (!/^\d+$/.test(t)) throw Error("Civitai 返回了无效的模型标识");
|
|
32
|
+
return t;
|
|
33
|
+
}
|
|
34
|
+
function l(e) {
|
|
35
|
+
return a(e).filter((e) => typeof e == "string");
|
|
36
|
+
}
|
|
37
|
+
function u(e) {
|
|
38
|
+
return o(e).replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, "").replace(/<br\s*\/?\s*>|<\/(?:p|div|h[1-6]|li)>/gi, "\n").replace(/<[^>]*>/g, "").replace(/&(?:amp|lt|gt|quot|apos|nbsp);/g, (e) => ({
|
|
39
|
+
"&": "&",
|
|
40
|
+
"<": "<",
|
|
41
|
+
">": ">",
|
|
42
|
+
""": "\"",
|
|
43
|
+
"'": "'",
|
|
44
|
+
" ": " "
|
|
45
|
+
})[e] || e).replace(/&#(x[0-9a-f]+|\d+);/gi, (e, t) => {
|
|
46
|
+
let n = t.toLowerCase().startsWith("x") ? parseInt(t.slice(1), 16) : Number(t);
|
|
47
|
+
return n > 0 && n <= 1114111 ? String.fromCodePoint(n) : "";
|
|
48
|
+
}).replace(/\n{3,}/g, "\n\n").trim();
|
|
49
|
+
}
|
|
50
|
+
function d(e) {
|
|
51
|
+
try {
|
|
52
|
+
let t = new URL(o(e));
|
|
53
|
+
return t.protocol === "https:" && !t.username && !t.password ? t.href : "";
|
|
54
|
+
} catch {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function f(e) {
|
|
59
|
+
let t = d(e);
|
|
60
|
+
if (!t) return "";
|
|
61
|
+
let n = new URL(t);
|
|
62
|
+
if (n.hostname === "image.civitai.com") {
|
|
63
|
+
let e = n.pathname.split("/").filter(Boolean);
|
|
64
|
+
e.length >= 4 && (n.pathname = `/${e[0]}/${e[1]}/anim=false,width=450,optimized=true/preview.jpeg`);
|
|
65
|
+
}
|
|
66
|
+
return n.href;
|
|
67
|
+
}
|
|
68
|
+
function p(e) {
|
|
69
|
+
return [...new Set(a(e).filter((e) => {
|
|
70
|
+
let t = i(e);
|
|
71
|
+
return t.type !== "video" && t.nsfw !== !0 && (!t.nsfwLevel || t.nsfwLevel === "None" || t.nsfwLevel === 1);
|
|
72
|
+
}).map((e) => f(i(e).url)).filter(Boolean))];
|
|
73
|
+
}
|
|
74
|
+
function m(e) {
|
|
75
|
+
let t = i(e);
|
|
76
|
+
return {
|
|
77
|
+
id: c(t.id),
|
|
78
|
+
name: o(t.name),
|
|
79
|
+
size: s(t.sizeKB ?? t.sizeKb) * 1024,
|
|
80
|
+
format: o(i(t.metadata).format) || o(t.type) || "未知格式",
|
|
81
|
+
primary: t.primary === !0,
|
|
82
|
+
downloadable: !!d(t.downloadUrl),
|
|
83
|
+
sha256: o(i(t.hashes).SHA256) || void 0,
|
|
84
|
+
metadata: i(t.metadata)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function h(e) {
|
|
88
|
+
let t = i(e);
|
|
89
|
+
return {
|
|
90
|
+
id: c(t.id),
|
|
91
|
+
name: o(t.name) || "未命名版本",
|
|
92
|
+
baseModel: o(t.baseModel),
|
|
93
|
+
createdAt: o(t.publishedAt) || o(t.createdAt),
|
|
94
|
+
changelog: u(t.description),
|
|
95
|
+
triggerWords: l(t.trainedWords),
|
|
96
|
+
thumbnails: p(t.images),
|
|
97
|
+
files: a(t.files).map(m).sort((e, t) => Number(!!t.primary) - Number(!!e.primary) || e.name.localeCompare(t.name))
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function g(e) {
|
|
101
|
+
let n = i(e), d = c(n.id), f = a(n.modelVersions).map(h), p = Object.entries(r).find(([, e]) => e?.toLowerCase() === o(n.type).toLowerCase())?.[0], m = i(n.stats);
|
|
102
|
+
return {
|
|
103
|
+
id: d,
|
|
104
|
+
name: o(n.name) || "未命名模型",
|
|
105
|
+
author: o(i(n.creator).username) || "未知作者",
|
|
106
|
+
description: u(n.description),
|
|
107
|
+
type: p ?? "other",
|
|
108
|
+
baseModel: f[0]?.baseModel || "未标注",
|
|
109
|
+
tags: l(n.tags),
|
|
110
|
+
thumbnails: n.nsfw === !0 ? [] : [...new Set(f.flatMap((e) => e.thumbnails || []))].slice(0, 12),
|
|
111
|
+
downloadCount: s(m.downloadCount),
|
|
112
|
+
rating: s(m.rating),
|
|
113
|
+
createdAt: o(n.createdAt) || f.at(-1)?.createdAt || "",
|
|
114
|
+
updatedAt: o(n.updatedAt) || f[0]?.createdAt || "",
|
|
115
|
+
pageUrl: `${t}/models/${d}`,
|
|
116
|
+
availability: n.mode === "Archived" ? "此模型已归档,暂不提供下载" : n.mode === "TakenDown" ? "此模型已下架" : void 0,
|
|
117
|
+
versions: f.map((e) => ({
|
|
118
|
+
...e,
|
|
119
|
+
thumbnails: n.nsfw === !0 ? [] : e.thumbnails
|
|
120
|
+
}))
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function _(e) {
|
|
124
|
+
let t = new URL(`${n}/models`);
|
|
125
|
+
t.searchParams.set("limit", String(Math.min(100, Math.max(1, e.limit)))), t.searchParams.set("nsfw", "false"), t.searchParams.set("primaryFileOnly", "true"), e.search.trim() && t.searchParams.set({
|
|
126
|
+
name: "query",
|
|
127
|
+
author: "username",
|
|
128
|
+
tag: "tag"
|
|
129
|
+
}[e.searchBy], e.search.trim());
|
|
130
|
+
for (let n of e.types) r[n] && t.searchParams.append("types", r[n]);
|
|
131
|
+
for (let n of e.baseModels) t.searchParams.append("baseModels", n);
|
|
132
|
+
return e.sort && t.searchParams.set("sort", e.sort), e.period && t.searchParams.set("period", e.period), e.cursor?.startsWith("cursor:") ? t.searchParams.set("cursor", e.cursor.slice(7)) : e.cursor?.startsWith("page:") && t.searchParams.set("page", e.cursor.slice(5)), t.href;
|
|
133
|
+
}
|
|
134
|
+
function v(e) {
|
|
135
|
+
if (e.nextCursor !== void 0 && e.nextCursor !== null && e.nextCursor !== "") return `cursor:${String(e.nextCursor)}`;
|
|
136
|
+
if (!e.nextPage) return;
|
|
137
|
+
let n = new URL(o(e.nextPage), t);
|
|
138
|
+
if (n.origin !== t || n.pathname !== "/api/v1/models") throw Error("Civitai 返回了无效的分页地址");
|
|
139
|
+
let r = n.searchParams.get("cursor");
|
|
140
|
+
if (r) return `cursor:${r}`;
|
|
141
|
+
let i = n.searchParams.get("page");
|
|
142
|
+
return i && /^\d+$/.test(i) ? `page:${i}` : void 0;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region packages/plugins/civitai/index.ts
|
|
146
|
+
var y = e({
|
|
147
|
+
id: "civitai",
|
|
148
|
+
modelMarkets: [{
|
|
149
|
+
id: "civitai",
|
|
150
|
+
name: "Civitai",
|
|
151
|
+
homepage: t,
|
|
152
|
+
apiOrigins: [t],
|
|
153
|
+
capabilities: {
|
|
154
|
+
types: Object.keys(r),
|
|
155
|
+
baseModels: /* @__PURE__ */ "SD 1.5,SD 2.1,SDXL 1.0,Pony,Illustrious,NoobAI,Flux.1 D,Flux.1 S,Pony V7,SDXL Lightning,SDXL Turbo,SD 3.5 Medium,SD 3.5 Large,SD 3.5 Large Turbo,Flux.1 Krea,Flux.1 Kontext,Flux.2 D,Qwen,HiDream,Chroma,Hunyuan Video,Wan Video,Wan Video 1.3B t2v,Wan Video 14B t2v,Wan Video 14B i2v 480p,Wan Video 14B i2v 720p,Wan Video 2.2 T2V-A14B,Wan Video 2.2 I2V-A14B,Wan Video 2.2 TI2V-5B".split(","),
|
|
156
|
+
searchBy: [
|
|
157
|
+
"name",
|
|
158
|
+
"author",
|
|
159
|
+
"tag"
|
|
160
|
+
],
|
|
161
|
+
sorts: [
|
|
162
|
+
{
|
|
163
|
+
label: "下载最多",
|
|
164
|
+
value: "Most Downloaded"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
label: "最新发布",
|
|
168
|
+
value: "Newest"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
label: "评分最高",
|
|
172
|
+
value: "Highest Rated"
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
periods: [
|
|
176
|
+
{
|
|
177
|
+
label: "全部时间",
|
|
178
|
+
value: "AllTime"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
label: "本月",
|
|
182
|
+
value: "Month"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
label: "本周",
|
|
186
|
+
value: "Week"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
label: "今天",
|
|
190
|
+
value: "Day"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
apiKey: {
|
|
194
|
+
label: "Civitai API Key",
|
|
195
|
+
helpUrl: `${t}/user/account`
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
async search(e, t) {
|
|
199
|
+
let n = i(await t.http.getJson(_(e)));
|
|
200
|
+
if (!Array.isArray(n.items)) throw Error("Civitai 返回了无效的模型列表");
|
|
201
|
+
let r = i(n.metadata);
|
|
202
|
+
return {
|
|
203
|
+
items: n.items.map(g),
|
|
204
|
+
nextCursor: v(r),
|
|
205
|
+
total: typeof r.totalItems == "number" ? r.totalItems : void 0
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
async getDetail(e, t) {
|
|
209
|
+
return g(await t.http.getJson(`${n}/models/${c(e)}`));
|
|
210
|
+
},
|
|
211
|
+
async resolveDownload(e, r) {
|
|
212
|
+
let o = i(await r.http.getJson(`${n}/model-versions/${c(e.versionId)}`));
|
|
213
|
+
if (c(o.modelId) !== e.modelId) throw Error("文件所属模型已变更,请刷新详情");
|
|
214
|
+
let s = a(o.files).find((t) => c(i(t).id) === e.fileId);
|
|
215
|
+
if (!s || !d(i(s).downloadUrl)) throw Error("此文件已不可下载,请刷新详情或查看原站");
|
|
216
|
+
let l = m(s), u = new URL(d(i(s).downloadUrl));
|
|
217
|
+
if (u.origin !== t || !u.pathname.startsWith("/api/download/models/")) throw Error("Civitai 返回了无效的文件下载地址");
|
|
218
|
+
return u.searchParams.set("fileId", l.id), {
|
|
219
|
+
url: await r.http.resolveDownload(u.href),
|
|
220
|
+
filename: l.name,
|
|
221
|
+
size: l.size
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}]
|
|
225
|
+
});
|
|
226
|
+
//#endregion
|
|
227
|
+
export { y as civitaiPlugin, y as default };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
{
|
|
2
|
+
"payload": "eyJzY2hlbWEiOjEsInBhY2thZ2VOYW1lIjoiQHN5bmNzaGlvL2thbm8tcGx1Z2luLWNpdml0YWkiLCJwbHVnaW5JZCI6ImNpdml0YWkiLCJ2ZXJzaW9uIjoiMi4wLjAiLCJmaWxlcyI6W3sicGF0aCI6InBhY2thZ2UuanNvbiIsInNpemUiOjU4Miwic2hhMjU2IjoiYzA4ODUwNWMxYTU1MTg4MDJiODVkODNkNzk3N2IxZGMzZTBiOGUxZmQxYzA0MzU1MGZhYjJjZTUzYTU3NThmNiJ9LHsicGF0aCI6InBsdWdpbi5qc29uIiwic2l6ZSI6NDEzLCJzaGEyNTYiOiJjYzA4ZjE0Nzg0MWI1MWU2MzRkY2ZlNGU4YmI5MWRlZmI4NjdhYzBkMjFiYzY1MzNhMjY3ODQ4MWYwYjY2YTc0In0seyJwYXRoIjoiZGlzdC9lbnRyeS5qcyIsInNpemUiOjc0NDQsInNoYTI1NiI6IjA5OWMxOTM1OTQ2MzFmNTFjNWUwMTllYmYzNDlkYThmMjgwYzEyNjgzYmE2NzBhMjk1YzdhZTk5YmE2NmU4MDMifV19",
|
|
3
|
+
"keyId": "release-1",
|
|
4
|
+
"signature": "oOOVQXC0sjkqsr46sd+lCr59nXo0D3yUi8XsFXVx7r4iEJRIE00NXhuB0VU78q5tBMdp21JXPQQJTMZDr+NfBQ=="
|
|
5
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syncshio/kano-plugin-civitai",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "浏览 Civitai 模型、版本和文件",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"kano-plugin"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
"plugin.json",
|
|
11
|
+
"dist",
|
|
12
|
+
"kano-release.json"
|
|
13
|
+
],
|
|
14
|
+
"kano": {
|
|
15
|
+
"manifest": "plugin.json"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "node ../../../scripts/build-plugins.mjs civitai"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@syncshio/kano-plugin-sdk": "file:../../../../kano-plugin-sdk"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/plugin.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifestVersion": 2,
|
|
3
|
+
"id": "civitai",
|
|
4
|
+
"name": "Civitai 模型市场",
|
|
5
|
+
"version": "2.0.0",
|
|
6
|
+
"description": "浏览 Civitai 模型、版本和文件",
|
|
7
|
+
"runtime": {
|
|
8
|
+
"entry": "dist/entry.js"
|
|
9
|
+
},
|
|
10
|
+
"permissions": {
|
|
11
|
+
"network": [
|
|
12
|
+
"https://civitai.com"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"kano": "^1.0.0",
|
|
17
|
+
"pluginSdk": "^4.0.0"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"kano-plugin",
|
|
21
|
+
"model-market"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/README.md
DELETED