dsh-think-skin 0.2.0 → 0.3.2

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.
Files changed (85) hide show
  1. package/README.md +16 -6
  2. package/assets/ClaudeCode/verbs.json +139 -135
  3. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274/Raid 1.gif +0 -0
  4. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274/Raid 2.gif +0 -0
  5. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//344/270/200/345/210/207/351/203/275/345/245/275 1.gif +0 -0
  6. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//344/270/273/346/204/217.gif +0 -0
  7. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/201/234/346/255/242/345/267/245/344/275/234.gif +0 -0
  8. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/202/254/347/234/240.gif +0 -0
  9. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/203/217/347/264/240/345/242/250/351/225/234/345/217/215/345/205/211.gif +0 -0
  10. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/217/271/345/217/267.gif +0 -0
  11. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/347/210/206/347/261/263/350/212/261).gif +0 -0
  12. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/347/224/234/347/224/234/345/234/210).gif +0 -0
  13. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/220/203(/350/245/277/347/223/234).gif +0 -0
  14. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/221/206(/350/264/264/347/272/270) 2.gif +0 -0
  15. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/224/261/346/255/214.gif +0 -0
  16. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/345/260/217/347/235/241).gif +0 -0
  17. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/346/231/256/351/200/232).gif +0 -0
  18. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/267/245/344/275/234(/347/226/262/345/200/246).gif +0 -0
  19. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//345/276/227/345/210/206(10/345/210/206).gif +0 -0
  20. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/200/235/350/200/203(/350/207/252/344/277/241/345/234/260).gif +0 -0
  21. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/200/235/350/200/203(/350/256/244/347/234/237/345/234/260).gif +0 -0
  22. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/346/201/274/346/200/222).gif +0 -0
  23. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/346/231/256/351/200/232).gif +0 -0
  24. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/345/255/227(/347/224/237/346/260/224).gif +0 -0
  25. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/211/223/346/270/270/346/210/217.gif +0 -0
  26. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/212/223/346/213/215(/346/211/213/346/234/272).gif +0 -0
  27. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/212/230/346/211/207.gif +0 -0
  28. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/214/211/351/222/256.gif +0 -0
  29. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//346/255/243/345/234/250/346/200/235/350/200/203.gif +0 -0
  30. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/210/261/345/277/203 2.gif +0 -0
  31. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/210/261/345/277/203 3.gif +0 -0
  32. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/265/351/243/216/346/211/207 1.gif +0 -0
  33. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/265/351/243/216/346/211/207 2.gif +0 -0
  34. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/224/273/346/235/277.gif +0 -0
  35. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/234/250/347/234/274.gif +0 -0
  36. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/235/241/350/247/211(/345/207/206/345/244/207/351/230/266/346/256/2651).gif +0 -0
  37. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//347/244/274/347/211/251 2.gif +0 -0
  38. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/242/253/345/207/273/344/270/255(Bits).gif +0 -0
  39. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/242/253/345/207/273/344/270/255(/347/210/261/345/277/203).gif +0 -0
  40. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//351/246/213(/345/210/200/345/217/211).gif +0 -0
  41. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//351/246/213(/347/255/267/345/255/220).gif +0 -0
  42. package/assets//351/205/222/347/213/220/PS2.gif +0 -0
  43. package/client.js +885 -32
  44. package/index.js +400 -0
  45. package/package.json +4 -2
  46. package/tools/compile-pack.py +117 -0
  47. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_Raid 1_2026-08-18-14-25-14.gif +0 -0
  48. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_Raid 2_2026-08-18-14-25-25.gif +0 -0
  49. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/344/270/200/345/210/207/351/203/275/345/245/275 1_2026-08-18-14-37-38.gif +0 -0
  50. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/344/270/273/346/204/217_2026-08-18-14-15-51.gif +0 -0
  51. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/201/234/346/255/242/345/267/245/344/275/234_2026-08-18-14-34-45.gif +0 -0
  52. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/202/254/347/234/240_2026-08-18-14-15-43.gif +0 -0
  53. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/203/217/347/264/240/345/242/250/351/225/234/345/217/215/345/205/211_2026-08-18-14-35-59.gif +0 -0
  54. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/217/271/345/217/267_2026-08-18-14-12-08.gif +0 -0
  55. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/347/210/206/347/261/263/350/212/261)_2026-08-18-14-11-25.gif +0 -0
  56. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/347/224/234/347/224/234/345/234/210)_2026-08-18-14-11-06.gif +0 -0
  57. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/220/203(/350/245/277/347/223/234)_2026-08-18-14-11-30.gif +0 -0
  58. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/221/206(/350/264/264/347/272/270) 2_2026-08-18-14-10-34.gif +0 -0
  59. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/224/261/346/255/214_2026-08-18-14-28-11.gif +0 -0
  60. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/345/260/217/347/235/241)_2026-08-18-14-39-08.gif +0 -0
  61. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/346/231/256/351/200/232)_2026-08-18-14-39-12.gif +0 -0
  62. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/267/245/344/275/234(/347/226/262/345/200/246)_2026-08-18-14-39-19.gif +0 -0
  63. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/345/276/227/345/210/206(10/345/210/206)_2026-08-18-14-27-16.gif +0 -0
  64. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/200/235/350/200/203(/350/207/252/344/277/241/345/234/260)_2026-08-18-14-37-20.gif +0 -0
  65. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/200/235/350/200/203(/350/256/244/347/234/237/345/234/260)_2026-08-18-14-37-25.gif +0 -0
  66. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/346/201/274/346/200/222)_2026-08-18-14-38-27.gif +0 -0
  67. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/346/231/256/351/200/232)_2026-08-18-14-38-34.gif +0 -0
  68. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/345/255/227(/347/224/237/346/260/224)_2026-08-18-14-38-24.gif +0 -0
  69. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/211/223/346/270/270/346/210/217_2026-08-18-14-13-01.gif +0 -0
  70. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/212/223/346/213/215(/346/211/213/346/234/272)_2026-08-18-14-04-40.gif +0 -0
  71. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/212/230/346/211/207_2026-08-18-14-12-51.gif +0 -0
  72. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/214/211/351/222/256_2026-08-18-14-03-53.gif +0 -0
  73. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/346/255/243/345/234/250/346/200/235/350/200/203_2026-08-18-14-24-28.gif +0 -0
  74. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/210/261/345/277/203 2_2026-08-18-14-20-22.gif +0 -0
  75. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/210/261/345/277/203 3_2026-08-18-14-20-29.gif +0 -0
  76. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/265/351/243/216/346/211/207 1_2026-08-18-14-11-56.gif +0 -0
  77. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/265/351/243/216/346/211/207 2_2026-08-18-14-12-00.gif +0 -0
  78. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/224/273/346/235/277_2026-08-18-14-36-39.gif +0 -0
  79. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/234/250/347/234/274_2026-08-18-14-38-44.gif +0 -0
  80. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/235/241/350/247/211(/345/207/206/345/244/207/351/230/266/346/256/2651)_2026-08-18-14-28-50.gif +0 -0
  81. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/347/244/274/347/211/251 2_2026-08-18-14-14-21.gif +0 -0
  82. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/350/242/253/345/207/273/344/270/255(Bits)_2026-08-18-14-13-19.gif +0 -0
  83. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/350/242/253/345/207/273/344/270/255(/347/210/261/345/277/203)_2026-08-18-14-13-47.gif +0 -0
  84. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/351/246/213(/345/210/200/345/217/211)_2026-08-18-14-09-51.gif +0 -0
  85. package/assets/compiled-128//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274//350/223/235/350/211/262/345/244/247/350/202/245/351/261/274_/351/246/213(/347/255/267/345/255/220)_2026-08-18-14-09-43.gif +0 -0
package/index.js CHANGED
@@ -15,6 +15,7 @@
15
15
  */
16
16
 
17
17
  import fs from 'node:fs/promises'
18
+ import zlib from 'node:zlib'
18
19
  import os from 'node:os'
19
20
  import path from 'node:path'
20
21
 
@@ -37,6 +38,135 @@ const MIME = {
37
38
  const MAX_BODY = 1 << 20
38
39
  /** Largest accepted image upload. */
39
40
  const MAX_IMAGE = 32 * 1024 * 1024
41
+ /** 套组文件(含 base64 图片)可以有几十 MB。 */
42
+ const MAX_PACK_FILE = 192 * 1024 * 1024
43
+
44
+ // ---------------------------------------------------------------- zip helpers
45
+
46
+ const CRC_TABLE = (() => {
47
+ const table = new Uint32Array(256)
48
+ for (let n = 0; n < 256; n += 1) {
49
+ let c = n
50
+ for (let k = 0; k < 8; k += 1) c = (c & 1) === 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1
51
+ table[n] = c >>> 0
52
+ }
53
+ return table
54
+ })()
55
+
56
+ function crc32(buffer) {
57
+ let c = 0xffffffff
58
+ for (let i = 0; i < buffer.length; i += 1) c = CRC_TABLE[(c ^ buffer[i]) & 0xff] ^ (c >>> 8)
59
+ return (c ^ 0xffffffff) >>> 0
60
+ }
61
+
62
+ /**
63
+ * Build a zip from `[{ name, data }]`.
64
+ *
65
+ * Entries deflate when that actually saves bytes, store otherwise — a GIF is
66
+ * already compressed, so most images end up stored and the archive stays close
67
+ * to the sum of the images. Names are flagged UTF-8 so non-ASCII pack names
68
+ * survive on every unzip tool.
69
+ */
70
+ function makeZip(files) {
71
+ const parts = []
72
+ const central = []
73
+ let offset = 0
74
+ for (const file of files) {
75
+ const name = Buffer.from(file.name, 'utf8')
76
+ const deflated = zlib.deflateRawSync(file.data)
77
+ const useDeflate = deflated.length < file.data.length
78
+ const body = useDeflate ? deflated : file.data
79
+ const method = useDeflate ? 8 : 0
80
+ const crc = crc32(file.data)
81
+
82
+ const local = Buffer.alloc(30)
83
+ local.writeUInt32LE(0x04034b50, 0)
84
+ local.writeUInt16LE(20, 4)
85
+ local.writeUInt16LE(0x0800, 6)
86
+ local.writeUInt16LE(method, 8)
87
+ local.writeUInt16LE(0, 10)
88
+ local.writeUInt16LE(0x21, 12)
89
+ local.writeUInt32LE(crc, 14)
90
+ local.writeUInt32LE(body.length, 18)
91
+ local.writeUInt32LE(file.data.length, 22)
92
+ local.writeUInt16LE(name.length, 26)
93
+ local.writeUInt16LE(0, 28)
94
+ parts.push(local, name, body)
95
+
96
+ const entry = Buffer.alloc(46)
97
+ entry.writeUInt32LE(0x02014b50, 0)
98
+ entry.writeUInt16LE(20, 4)
99
+ entry.writeUInt16LE(20, 6)
100
+ entry.writeUInt16LE(0x0800, 8)
101
+ entry.writeUInt16LE(method, 10)
102
+ entry.writeUInt16LE(0, 12)
103
+ entry.writeUInt16LE(0x21, 14)
104
+ entry.writeUInt32LE(crc, 16)
105
+ entry.writeUInt32LE(body.length, 20)
106
+ entry.writeUInt32LE(file.data.length, 24)
107
+ entry.writeUInt16LE(name.length, 28)
108
+ entry.writeUInt16LE(0, 30)
109
+ entry.writeUInt16LE(0, 32)
110
+ entry.writeUInt16LE(0, 34)
111
+ entry.writeUInt16LE(0, 36)
112
+ entry.writeUInt32LE(0, 38)
113
+ entry.writeUInt32LE(offset, 42)
114
+ central.push(entry, name)
115
+
116
+ offset += local.length + name.length + body.length
117
+ }
118
+
119
+ const directory = Buffer.concat(central)
120
+ const end = Buffer.alloc(22)
121
+ end.writeUInt32LE(0x06054b50, 0)
122
+ end.writeUInt16LE(0, 4)
123
+ end.writeUInt16LE(0, 6)
124
+ end.writeUInt16LE(files.length, 8)
125
+ end.writeUInt16LE(files.length, 10)
126
+ end.writeUInt32LE(directory.length, 12)
127
+ end.writeUInt32LE(offset, 16)
128
+ end.writeUInt16LE(0, 20)
129
+ return Buffer.concat([...parts, directory, end])
130
+ }
131
+
132
+ /** Read a zip into `Map<name, Buffer>`. Handles stored and deflated entries. */
133
+ function readZip(buffer) {
134
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
135
+ let end = -1
136
+ const floor = Math.max(0, buffer.length - 22 - 0xffff)
137
+ for (let i = buffer.length - 22; i >= floor; i -= 1) {
138
+ if (view.getUint32(i, true) === 0x06054b50) {
139
+ end = i
140
+ break
141
+ }
142
+ }
143
+ if (end < 0) throw new Error('不是 zip 文件')
144
+
145
+ const count = view.getUint16(end + 10, true)
146
+ let cursor = view.getUint32(end + 16, true)
147
+ const files = new Map()
148
+ for (let i = 0; i < count; i += 1) {
149
+ if (view.getUint32(cursor, true) !== 0x02014b50) break
150
+ const method = view.getUint16(cursor + 10, true)
151
+ const compressedSize = view.getUint32(cursor + 20, true)
152
+ const nameLength = view.getUint16(cursor + 28, true)
153
+ const extraLength = view.getUint16(cursor + 30, true)
154
+ const commentLength = view.getUint16(cursor + 32, true)
155
+ const localOffset = view.getUint32(cursor + 42, true)
156
+ const name = buffer
157
+ .subarray(cursor + 46, cursor + 46 + nameLength)
158
+ .toString('utf8')
159
+
160
+ const localName = view.getUint16(localOffset + 26, true)
161
+ const localExtra = view.getUint16(localOffset + 28, true)
162
+ const start = localOffset + 30 + localName + localExtra
163
+ const raw = buffer.subarray(start, start + compressedSize)
164
+ files.set(name, method === 8 ? zlib.inflateRawSync(raw) : Buffer.from(raw))
165
+
166
+ cursor += 46 + nameLength + extraLength + commentLength
167
+ }
168
+ return files
169
+ }
40
170
 
41
171
  /** Root of this plugin's data directory. */
42
172
  export function dataRoot() {
@@ -231,6 +361,30 @@ export function apply(ctx) {
231
361
  if (Number.isFinite(speed) && speed >= 1 && speed <= 60) {
232
362
  target.appearance = { ...(target.appearance || {}), speed }
233
363
  }
364
+ // 字形包的旋转参数:模式 / 帧间隔 / 颜色(空 = 跟主题)
365
+ if (patch.spinner !== undefined && patch.spinner !== null && typeof patch.spinner === 'object') {
366
+ const next = { ...(target.spinner || {}) }
367
+ if (patch.spinner.mode === 'braille' || patch.spinner.mode === 'glyph') {
368
+ next.mode = patch.spinner.mode
369
+ }
370
+ const interval = Number(patch.spinner.interval)
371
+ if (Number.isFinite(interval) && interval >= 16 && interval <= 6000) {
372
+ next.interval = Math.round(interval)
373
+ }
374
+ // 字符画的一整趟时长,和盲文的帧间隔分开存
375
+ const period = Number(patch.spinner.period)
376
+ if (Number.isFinite(period) && period >= 200 && period <= 6000) {
377
+ next.period = Math.round(period)
378
+ }
379
+ if (typeof patch.spinner.color === 'string') {
380
+ if (patch.spinner.color === '') delete next.color
381
+ else if (/^#[0-9a-f]{3,8}$/i.test(patch.spinner.color)) next.color = patch.spinner.color
382
+ }
383
+ if (Array.isArray(patch.spinner.frames) && patch.spinner.frames.length > 1) {
384
+ next.frames = patch.spinner.frames.filter((f) => typeof f === 'string' && f.length > 0)
385
+ }
386
+ target.spinner = next
387
+ }
234
388
  const fallback = cleanLines(patch.fallbackTexts)
235
389
  if (fallback !== null) target.fallbackTexts = fallback
236
390
  if (typeof patch.cover === 'string' && patch.cover.length > 0) target.cover = patch.cover
@@ -393,4 +547,250 @@ export function apply(ctx) {
393
547
  })
394
548
 
395
549
  ctx.effect(() => disposeUpload)
550
+
551
+ /**
552
+ * Export one pack as a self-contained JSON document.
553
+ *
554
+ * Images travel as base64 inside the file, so a pack can be handed to someone
555
+ * else as one attachment with no side files and no URLs that rot.
556
+ */
557
+ const disposeExport = ctx.webServer.register({
558
+ kind: 'exact',
559
+ path: ROUTE + '/export',
560
+ async handler(req, res) {
561
+ const fail = (status, message) => {
562
+ res.writeHead(status, { 'content-type': 'text/plain; charset=utf-8' })
563
+ res.end(message)
564
+ }
565
+ if (req.method !== 'POST') return fail(405, 'method not allowed')
566
+ try {
567
+ const body = JSON.parse((await readBody(req, MAX_BODY)).toString('utf8'))
568
+ const data = await load()
569
+ const pack = data.packs.find((p) => p.id === body.pack)
570
+ if (pack === undefined) return fail(404, '没有这个套')
571
+
572
+ // zip: pack.json + images/<name>,图片原样存,不经 base64
573
+ const entries = []
574
+ const images = []
575
+ let index = 0
576
+ for (const image of pack.images) {
577
+ const file = path.join(root, 'images', image.file.replace('/', path.sep))
578
+ let bytes = null
579
+ try {
580
+ bytes = await fs.readFile(file)
581
+ } catch {
582
+ bytes = null
583
+ }
584
+ if (bytes === null) continue
585
+ index += 1
586
+ const ext = path.extname(image.file).toLowerCase() || '.gif'
587
+ const name = 'images/i' + String(index).padStart(3, '0') + ext
588
+ entries.push({ name, data: bytes })
589
+ images.push({
590
+ id: image.id,
591
+ name: image.name,
592
+ texts: Array.isArray(image.texts) ? image.texts : [],
593
+ useFallback: image.useFallback !== false,
594
+ file: name,
595
+ sourceFile: image.file,
596
+ })
597
+ }
598
+
599
+ const manifest = {
600
+ format: 'dsh-think-skin/pack',
601
+ version: 2,
602
+ exportedAt: new Date().toISOString(),
603
+ pack: {
604
+ id: pack.id,
605
+ name: pack.name,
606
+ appearance: pack.appearance || {},
607
+ fallbackTexts: Array.isArray(pack.fallbackTexts) ? pack.fallbackTexts : [],
608
+ spinner: pack.spinner === undefined ? null : pack.spinner,
609
+ cover: (images.find((i) => i.sourceFile === pack.cover) || images[0] || {}).file || null,
610
+ images,
611
+ },
612
+ }
613
+ entries.unshift({ name: 'pack.json', data: Buffer.from(JSON.stringify(manifest, null, 1), 'utf8') })
614
+
615
+ const zip = makeZip(entries)
616
+ res.writeHead(200, {
617
+ 'content-type': 'application/zip',
618
+ 'content-disposition': 'attachment; filename="pack.zip"',
619
+ 'cache-control': 'no-store',
620
+ 'content-length': String(zip.length),
621
+ })
622
+ res.end(zip)
623
+ } catch (error) {
624
+ fail(400, String((error && error.message) || error))
625
+ }
626
+ },
627
+ })
628
+
629
+ ctx.effect(() => disposeExport)
630
+
631
+ /** Pick a pack id that is not taken yet. */
632
+ function freePackId(taken, wanted) {
633
+ if (!taken.has(wanted)) return wanted
634
+ for (let n = 2; n < 1000; n += 1) {
635
+ const candidate = wanted + ' ' + n
636
+ if (!taken.has(candidate)) return candidate
637
+ }
638
+ return wanted + ' ' + Date.now()
639
+ }
640
+
641
+ /**
642
+ * Import a pack document, copying every image into the store.
643
+ *
644
+ * Accepts either an inline document or a URL to fetch on the host, which
645
+ * sidesteps CORS and hotlink referer checks that a browser fetch would hit.
646
+ */
647
+ const disposeImport = ctx.webServer.register({
648
+ kind: 'exact',
649
+ path: ROUTE + '/import',
650
+ async handler(req, res) {
651
+ const fail = (status, message) => {
652
+ res.writeHead(status, { 'content-type': 'text/plain; charset=utf-8' })
653
+ res.end(message)
654
+ }
655
+ if (req.method !== 'POST') return fail(405, 'method not allowed')
656
+ let dir = null
657
+ try {
658
+ const body = await readBody(req, MAX_PACK_FILE)
659
+ const type = String(req.headers['content-type'] || '')
660
+
661
+ // 三种来源:zip 字节(本地/URL 下载)、旧版 JSON 载荷、服务端下载 URL
662
+ let document = null
663
+ let zipFiles = null
664
+
665
+ if (type.startsWith('application/zip')) {
666
+ zipFiles = readZip(body)
667
+ const manifest = zipFiles.get('pack.json')
668
+ if (manifest === undefined) return fail(400, '压缩包里没有 pack.json')
669
+ document = JSON.parse(manifest.toString('utf8'))
670
+ } else {
671
+ const request = JSON.parse(body.toString('utf8'))
672
+ if (request.file !== undefined) {
673
+ document = request.file
674
+ } else if (typeof request.url === 'string') {
675
+ let response
676
+ try {
677
+ response = await fetch(request.url, { redirect: 'follow' })
678
+ } catch (error) {
679
+ return fail(400, '下载失败:' + String((error && error.message) || error))
680
+ }
681
+ if (!response.ok) return fail(400, '下载失败:HTTP ' + response.status)
682
+ const downloaded = Buffer.from(await response.arrayBuffer())
683
+
684
+ // 网盘分享页、登录页、错误页都会返回 HTML;直接说清楚,别让用户猜
685
+ const head = downloaded.subarray(0, 512).toString('utf8').trim().toLowerCase()
686
+ const contentType = String(response.headers.get('content-type') || '').toLowerCase()
687
+ if (contentType.includes('text/html') || head.startsWith('<!doctype') || head.startsWith('<html')) {
688
+ return fail(
689
+ 400,
690
+ '这个 URL 返回的是网页,不是文件。网盘分享页和需要登录的链接都不行,'
691
+ + '请用直链(对象存储、GitHub raw、你自己的静态服务器等)。',
692
+ )
693
+ }
694
+ const looksZip = downloaded.length > 4 && downloaded.readUInt32LE(0) === 0x04034b50
695
+ if (looksZip) {
696
+ zipFiles = readZip(downloaded)
697
+ const manifest = zipFiles.get('pack.json')
698
+ if (manifest === undefined) return fail(400, '压缩包里没有 pack.json')
699
+ document = JSON.parse(manifest.toString('utf8'))
700
+ } else {
701
+ document = JSON.parse(downloaded.toString('utf8'))
702
+ }
703
+ }
704
+ }
705
+ if (document === null || typeof document !== 'object') return fail(400, '没有内容')
706
+ if (document.format !== 'dsh-think-skin/pack') return fail(400, '不是套组文件')
707
+ const source = document.pack
708
+ if (source === null || typeof source !== 'object') return fail(400, '套组内容缺失')
709
+ const images = Array.isArray(source.images) ? source.images : []
710
+
711
+ const data = await load()
712
+ const taken = new Set(data.packs.map((p) => p.id))
713
+ const base = typeof source.id === 'string' && source.id.trim() !== ''
714
+ ? source.id.trim()
715
+ : '导入的套'
716
+ const id = freePackId(taken, base)
717
+
718
+ dir = path.join(root, 'images', id)
719
+ await fs.mkdir(dir, { recursive: true })
720
+
721
+ const stored = []
722
+ let cover = null
723
+ for (let index = 0; index < images.length; index += 1) {
724
+ const image = images[index]
725
+ const sourceName = typeof image.file === 'string' ? image.file : 'f.gif'
726
+ const ext = path.extname(sourceName).toLowerCase()
727
+ if (!Object.prototype.hasOwnProperty.call(MIME, ext)) continue
728
+ let bytes = null
729
+ if (zipFiles !== null) {
730
+ bytes = zipFiles.get(sourceName) === undefined ? null : zipFiles.get(sourceName)
731
+ } else if (typeof image.data === 'string' && image.data.length > 0) {
732
+ bytes = Buffer.from(image.data, 'base64')
733
+ }
734
+ if (bytes === null) continue
735
+ const file = 'i' + String(index + 1).padStart(3, '0') + ext
736
+ await fs.writeFile(path.join(dir, file), bytes)
737
+ stored.push({
738
+ id: file.slice(0, -ext.length),
739
+ file: id + '/' + file,
740
+ name: typeof image.name === 'string' ? image.name : '',
741
+ texts: Array.isArray(image.texts) ? image.texts : [],
742
+ useFallback: image.useFallback !== false,
743
+ })
744
+ if (image.file === source.cover) cover = id + '/' + file
745
+ }
746
+ if (stored.length === 0) return fail(400, '套组里没有可导入的图片')
747
+
748
+ // 用户在导入页换过封面:按文件名对上,覆盖清单里的默认值
749
+ const wanted = req.headers['x-ts-cover']
750
+ if (typeof wanted === 'string' && wanted !== '') {
751
+ try {
752
+ const base = path.basename(decodeURIComponent(wanted))
753
+ const hit = stored.find((entry) => path.basename(entry.file) === base)
754
+ if (hit !== undefined) cover = hit.file
755
+ } catch {
756
+ /* 头部解不开就沿用清单里的封面 */
757
+ }
758
+ }
759
+ if (cover === null) cover = stored[0].file
760
+
761
+ data.packs.push({
762
+ id,
763
+ name: id,
764
+ builtin: false,
765
+ cover,
766
+ fallbackTexts: Array.isArray(source.fallbackTexts) && source.fallbackTexts.length > 0
767
+ ? source.fallbackTexts
768
+ : ['正在思考'],
769
+ appearance: source.appearance !== null && typeof source.appearance === 'object'
770
+ ? source.appearance
771
+ : {},
772
+ spinner: source.spinner !== null && typeof source.spinner === 'object'
773
+ ? source.spinner
774
+ : null,
775
+ images: stored,
776
+ })
777
+ if (!data.active) data.active = id
778
+ await save(data)
779
+
780
+ const payload = JSON.stringify({ ok: true, pack: id, images: stored.length, cover })
781
+ res.writeHead(200, {
782
+ 'content-type': 'application/json; charset=utf-8',
783
+ 'cache-control': 'no-store',
784
+ 'content-length': String(Buffer.byteLength(payload)),
785
+ })
786
+ res.end(payload)
787
+ } catch (error) {
788
+ if (dir !== null) await fs.rm(dir, { recursive: true, force: true }).catch(() => {})
789
+ fail(400, String((error && error.message) || error))
790
+ }
791
+ },
792
+ })
793
+
794
+ ctx.effect(() => disposeImport)
795
+
396
796
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-think-skin",
3
- "version": "0.2.0",
3
+ "version": "0.3.2",
4
4
  "description": "Reskin the DSH thinking row: your own image, your own words, double random.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,7 +31,9 @@
31
31
  "assets/cover.gif",
32
32
  "assets/compiled-128",
33
33
  "assets/ClaudeCode/verbs.json",
34
- "assets/ClaudeCode/placeholder.png"
34
+ "assets/ClaudeCode/placeholder.png",
35
+ "assets/酒狐",
36
+ "tools/compile-pack.py"
35
37
  ],
36
38
  "dsh": {
37
39
  "bundle": {
@@ -0,0 +1,117 @@
1
+ """Recompile a pack's images at 128px, keeping every frame and its delay.
2
+
3
+ The rule this file exists to protect: **never rewrite per-frame timing.** A GIF
4
+ carries its own cadence — the fish sources run at 20 ms per frame, the fox at
5
+ 100 ms. Forcing a fixed frame rate is what made the fox spin twice too fast and
6
+ cost the fish two thirds of its frames.
7
+
8
+ Usage:
9
+ python tools/compile-pack.py --pack 蓝色大肥鱼 --source assets/蓝色大肥鱼
10
+ python tools/compile-pack.py --pack 酒狐 --source assets/酒狐
11
+ python tools/compile-pack.py --pack 蓝色大肥鱼 --source ... --dry-run
12
+ """
13
+
14
+ import argparse
15
+ import io
16
+ import json
17
+ import os
18
+ import re
19
+ import sys
20
+
21
+ try:
22
+ from PIL import Image, ImageSequence
23
+ except ImportError:
24
+ sys.exit("需要 Pillow:pip install pillow")
25
+
26
+ HERE = os.path.dirname(os.path.abspath(__file__))
27
+ ROOT = os.path.dirname(HERE)
28
+ BOX = (128, 128)
29
+
30
+
31
+ def store_root():
32
+ home = os.environ.get("DSH_HOME") or os.path.join(os.path.expanduser("~"), ".dsh")
33
+ return os.path.join(home, "storages", "think_skin")
34
+
35
+
36
+ def action_of(filename):
37
+ """`蓝色大肥鱼_思考(认真地)_2026-08-18-14-37-25.gif` -> `思考(认真地)`."""
38
+ stem = os.path.splitext(os.path.basename(filename))[0]
39
+ stem = re.sub(r"_\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}$", "", stem)
40
+ stem = re.sub(r"^[^_]+_", "", stem)
41
+ return stem.strip()
42
+
43
+
44
+ def compile_gif(src, dst):
45
+ """Resize every frame to fit BOX, preserving the frame count and delays."""
46
+ im = Image.open(src)
47
+ frames = []
48
+ durations = []
49
+ for frame in ImageSequence.Iterator(im):
50
+ durations.append(frame.info.get("duration", 100) or 100)
51
+ rgba = frame.convert("RGBA")
52
+ w, h = rgba.size
53
+ scale = min(BOX[0] / w, BOX[1] / h)
54
+ size = (max(1, int(round(w * scale))), max(1, int(round(h * scale))))
55
+ scaled = rgba.resize(size, Image.LANCZOS)
56
+ canvas = Image.new("RGBA", BOX, (0, 0, 0, 0))
57
+ canvas.paste(scaled, ((BOX[0] - size[0]) // 2, (BOX[1] - size[1]) // 2), scaled)
58
+ frames.append(canvas)
59
+ frames[0].save(
60
+ dst,
61
+ save_all=True,
62
+ append_images=frames[1:],
63
+ duration=durations,
64
+ loop=0,
65
+ disposal=2,
66
+ optimize=True,
67
+ )
68
+ return len(frames), sum(durations)
69
+
70
+
71
+ def main():
72
+ parser = argparse.ArgumentParser()
73
+ parser.add_argument("--pack", required=True, help="pack id in pack.json")
74
+ parser.add_argument("--source", required=True, help="directory of original GIFs")
75
+ parser.add_argument("--dry-run", action="store_true")
76
+ args = parser.parse_args()
77
+
78
+ manifest_path = os.path.join(store_root(), "pack.json")
79
+ document = json.load(io.open(manifest_path, encoding="utf-8"))
80
+ pack = next((p for p in document["packs"] if p["id"] == args.pack), None)
81
+ if pack is None:
82
+ sys.exit("pack.json 里没有 " + args.pack)
83
+
84
+ sources = {}
85
+ for name in os.listdir(args.source):
86
+ path = os.path.join(args.source, name)
87
+ if os.path.splitext(name)[1].lower() != ".gif":
88
+ continue
89
+ sources[action_of(name)] = path
90
+
91
+ print("源目录 %d 个 GIF,清单 %d 张图" % (len(sources), len(pack["images"])))
92
+ before = 0
93
+ after = 0
94
+ missing = []
95
+ for image in pack["images"]:
96
+ target = os.path.join(store_root(), "images", image["file"].replace("/", os.sep))
97
+ if os.path.exists(target):
98
+ before += os.path.getsize(target)
99
+ src = sources.get(image.get("name", ""))
100
+ if src is None:
101
+ missing.append(image.get("name", "?"))
102
+ continue
103
+ if args.dry_run:
104
+ continue
105
+ frames, total = compile_gif(src, target)
106
+ after += os.path.getsize(target)
107
+ print(" %-16s %3d 帧 %.2fs %4d KB" % (
108
+ image.get("name", "")[:16], frames, total / 1000, os.path.getsize(target) // 1024))
109
+
110
+ if missing:
111
+ print("没找到源文件: " + ", ".join(missing))
112
+ if not args.dry_run:
113
+ print("合计 %.2f MB → %.2f MB" % (before / 1024 / 1024, after / 1024 / 1024))
114
+
115
+
116
+ if __name__ == "__main__":
117
+ main()