dsh-think-skin 1.0.2 → 1.1.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.
- package/README.md +18 -0
- package/assets/music//351/205/222/347/213/220//346/234/213/345/217/213/347/232/204/351/205/222 1.ogg +0 -0
- package/assets/music//351/205/222/347/213/220//346/234/213/345/217/213/347/232/204/351/205/222 2.ogg +0 -0
- package/assets/music//351/205/222/347/213/220//346/234/213/345/217/213/347/232/204/351/205/222 3.ogg +0 -0
- package/client.js +636 -5
- package/index.js +347 -5
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -25,6 +25,24 @@ more than the answer. This replaces its icon and its copy, and keeps the timer.
|
|
|
25
25
|
导出/导入 .zip、字形参数与实时预览
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
### 音乐(1.1.0)
|
|
29
|
+
|
|
30
|
+
思考那一行出现时可以放歌,行消失就淡出。音乐不进来路不明的默认曲库——**全部由你自己导入**,
|
|
31
|
+
所以也没有版权问题。
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
位置 设置 → 思考状态:顶部有总开关 + 音量滑轨;每张图的详情里有它自己的音乐池,
|
|
35
|
+
通用池下面有这一套共用的音��池
|
|
36
|
+
抽取 三种模式,根菜单里选:随机(洗牌袋一轮不重复)/ 顺序(按池子顺序走)/
|
|
37
|
+
单曲循环(这一轮认定一首,一直重放)
|
|
38
|
+
内置 酒狐自带《朋友的酒》三段(共 76 秒,0.63 MB),装完就有;
|
|
39
|
+
删掉的话下次启动会重新出现
|
|
40
|
+
转场 进 0.2 秒淡入,出 0.3 秒淡出;一首放完先淡出再从池里抽下一首
|
|
41
|
+
导出 音乐随套组 zip 一起走,导入时复制进 storages,不引用你硬盘上的原文件
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
建议导入一首歌的**几段**而不是整首——抽起来才有换歌的感觉,也不用我们做静音切片。
|
|
45
|
+
|
|
28
46
|
**双随机:** 一次运行抽一张图(整轮固定),图再带自己的文案池,池里每 7–15 秒抽一句。
|
|
29
47
|
两个随机在不同尺度上,组合数远大于单池。
|
|
30
48
|
|
package/assets/music//351/205/222/347/213/220//346/234/213/345/217/213/347/232/204/351/205/222 1.ogg
ADDED
|
Binary file
|
package/assets/music//351/205/222/347/213/220//346/234/213/345/217/213/347/232/204/351/205/222 2.ogg
ADDED
|
Binary file
|
package/assets/music//351/205/222/347/213/220//346/234/213/345/217/213/347/232/204/351/205/222 3.ogg
ADDED
|
Binary file
|
package/client.js
CHANGED
|
@@ -193,6 +193,18 @@ window.__ModuleLoader__.load({
|
|
|
193
193
|
.then((data) => {
|
|
194
194
|
const packs = Array.isArray(data.packs) ? data.packs : []
|
|
195
195
|
pack = packs.find((entry) => entry.id === data.active) || packs[0] || null
|
|
196
|
+
if (data.settings !== undefined && data.settings !== null) {
|
|
197
|
+
docSettings = {
|
|
198
|
+
musicEnabled: data.settings.musicEnabled !== false,
|
|
199
|
+
musicVolume: Number.isFinite(Number(data.settings.musicVolume))
|
|
200
|
+
? Number(data.settings.musicVolume)
|
|
201
|
+
: 40,
|
|
202
|
+
musicMode: ['random', 'sequential', 'single'].includes(data.settings.musicMode)
|
|
203
|
+
? data.settings.musicMode
|
|
204
|
+
: 'random',
|
|
205
|
+
}
|
|
206
|
+
Music.applyVolume()
|
|
207
|
+
}
|
|
196
208
|
return pack
|
|
197
209
|
})
|
|
198
210
|
.catch(() => null)
|
|
@@ -577,6 +589,370 @@ window.__ModuleLoader__.load({
|
|
|
577
589
|
}
|
|
578
590
|
}
|
|
579
591
|
|
|
592
|
+
// ---------------------------------------------------------------- music
|
|
593
|
+
|
|
594
|
+
/** 文档根部的音乐设置,loadPack 时顺手抓下来。 */
|
|
595
|
+
let docSettings = { musicEnabled: true, musicVolume: 40, musicMode: 'random' }
|
|
596
|
+
|
|
597
|
+
function musicUrl(file) {
|
|
598
|
+
return ROUTE + '/music/' + encodeURI(file)
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** 当前这一行用哪一组音乐:本图的池,加上(默认)通用池。 */
|
|
602
|
+
function musicPoolOf(state) {
|
|
603
|
+
if (pack === null || state === null || state === undefined) return []
|
|
604
|
+
const merged = []
|
|
605
|
+
const image = state.image
|
|
606
|
+
if (image !== undefined && image !== null && Array.isArray(image.music)) {
|
|
607
|
+
for (const track of image.music) merged.push(track)
|
|
608
|
+
}
|
|
609
|
+
if (image === undefined || image === null || image.useFallbackMusic !== false) {
|
|
610
|
+
for (const track of Array.isArray(pack.fallbackMusic) ? pack.fallbackMusic : []) {
|
|
611
|
+
merged.push(track)
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return merged
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* 思考行出现时放歌:单例、洗牌袋、极短淡入淡出。
|
|
619
|
+
*
|
|
620
|
+
* 不走 <audio>:那条路由整块返回字节,而音频元素会先探测长度、按 Range 分块取。
|
|
621
|
+
* 空闲时把 AudioContext 挂起 —— 一直 running 会让系统不敢进休眠。
|
|
622
|
+
*/
|
|
623
|
+
const Music = (typeof window !== 'undefined' && window.__tsMusic !== undefined)
|
|
624
|
+
? window.__tsMusic
|
|
625
|
+
: (() => {
|
|
626
|
+
let audio = null
|
|
627
|
+
let master = null
|
|
628
|
+
let playing = null // 正在放的曲目 id
|
|
629
|
+
let active = false // 思考行是否在
|
|
630
|
+
let starting = false // 有一次 play 还在 await,期间不许再起
|
|
631
|
+
let pool = []
|
|
632
|
+
let poolKey = ''
|
|
633
|
+
let bag = []
|
|
634
|
+
let seqIndex = 0
|
|
635
|
+
let sessionTrack = null
|
|
636
|
+
let token = 0
|
|
637
|
+
let idleTimer = 0
|
|
638
|
+
const live = new Set() // 所有没停掉的音源:万一有漏网的,也一定能一起叫停
|
|
639
|
+
const cache = new Map()
|
|
640
|
+
|
|
641
|
+
function ensure() {
|
|
642
|
+
if (audio !== null) return audio
|
|
643
|
+
const AC = window.AudioContext || window.webkitAudioContext
|
|
644
|
+
if (AC === undefined) return null
|
|
645
|
+
try {
|
|
646
|
+
audio = new AC()
|
|
647
|
+
master = audio.createGain()
|
|
648
|
+
master.gain.value = volumeGain()
|
|
649
|
+
master.connect(audio.destination)
|
|
650
|
+
} catch {
|
|
651
|
+
audio = null
|
|
652
|
+
master = null
|
|
653
|
+
}
|
|
654
|
+
return audio
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function volumeGain() {
|
|
658
|
+
const raw = Number(docSettings.musicVolume)
|
|
659
|
+
const v = Number.isFinite(raw) ? Math.max(0, Math.min(100, raw)) : 40
|
|
660
|
+
return Math.pow(v / 100, 1.7) * 0.9
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function unlock() {
|
|
664
|
+
const ac = ensure()
|
|
665
|
+
if (ac === null) return Promise.resolve()
|
|
666
|
+
if (ac.state === 'suspended') return ac.resume().catch(() => {})
|
|
667
|
+
return Promise.resolve()
|
|
668
|
+
}
|
|
669
|
+
if (typeof document !== 'undefined') {
|
|
670
|
+
const once = () => {
|
|
671
|
+
unlock()
|
|
672
|
+
document.removeEventListener('pointerdown', once, true)
|
|
673
|
+
document.removeEventListener('keydown', once, true)
|
|
674
|
+
}
|
|
675
|
+
document.addEventListener('pointerdown', once, true)
|
|
676
|
+
document.addEventListener('keydown', once, true)
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function idle() {
|
|
680
|
+
clearTimeout(idleTimer)
|
|
681
|
+
idleTimer = setTimeout(() => {
|
|
682
|
+
if (audio !== null && playing === null && live.size === 0 && audio.state === 'running') {
|
|
683
|
+
audio.suspend().catch(() => {})
|
|
684
|
+
}
|
|
685
|
+
}, 20000)
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
async function bytes(file) {
|
|
689
|
+
if (cache.has(file)) return cache.get(file)
|
|
690
|
+
try {
|
|
691
|
+
const response = await fetch(musicUrl(file), { cache: 'force-cache' })
|
|
692
|
+
if (!response.ok) return null
|
|
693
|
+
const buffer = await response.arrayBuffer()
|
|
694
|
+
cache.set(file, buffer)
|
|
695
|
+
while (cache.size > 3) cache.delete(cache.keys().next().value)
|
|
696
|
+
return buffer
|
|
697
|
+
} catch {
|
|
698
|
+
return null
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function shuffle() {
|
|
703
|
+
bag = pool.slice()
|
|
704
|
+
for (let i = bag.length - 1; i > 0; i -= 1) {
|
|
705
|
+
const j = Math.floor(Math.random() * (i + 1))
|
|
706
|
+
const tmp = bag[i]
|
|
707
|
+
bag[i] = bag[j]
|
|
708
|
+
bag[j] = tmp
|
|
709
|
+
}
|
|
710
|
+
if (bag.length > 1 && bag[0].id === playing) {
|
|
711
|
+
const tmp = bag[0]
|
|
712
|
+
bag[0] = bag[1]
|
|
713
|
+
bag[1] = tmp
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function pick() {
|
|
718
|
+
if (pool.length === 0) return null
|
|
719
|
+
const mode = docSettings.musicMode
|
|
720
|
+
|
|
721
|
+
// 单曲循环:这一轮思考就认定一首,之后一直重放它
|
|
722
|
+
if (mode === 'single') {
|
|
723
|
+
if (sessionTrack === null) {
|
|
724
|
+
sessionTrack = pool[Math.floor(Math.random() * pool.length)]
|
|
725
|
+
}
|
|
726
|
+
return pool.find((t) => t.id === sessionTrack.id) || sessionTrack
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// 顺序:按池子里的顺序走,到头回到第一首
|
|
730
|
+
if (mode === 'sequential') {
|
|
731
|
+
const track = pool[seqIndex % pool.length]
|
|
732
|
+
seqIndex = (seqIndex + 1) % pool.length
|
|
733
|
+
return track
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// 随机:洗牌袋,一轮不重复
|
|
737
|
+
if (bag.length === 0) shuffle()
|
|
738
|
+
return bag.shift() || null
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** 停掉每一路音源(可带淡出),并把它们从活音源集合里清掉。 */
|
|
742
|
+
function killAll(fadeMs) {
|
|
743
|
+
const dying = Array.from(live)
|
|
744
|
+
live.clear()
|
|
745
|
+
for (const node of dying) {
|
|
746
|
+
try {
|
|
747
|
+
if (fadeMs > 0) {
|
|
748
|
+
const now = audio === null ? 0 : audio.currentTime
|
|
749
|
+
node.gain.gain.cancelScheduledValues(now)
|
|
750
|
+
node.gain.gain.setValueAtTime(node.gain.gain.value, now)
|
|
751
|
+
node.gain.gain.linearRampToValueAtTime(0.0001, now + fadeMs / 1000)
|
|
752
|
+
}
|
|
753
|
+
} catch {
|
|
754
|
+
/* 节点可能已经断了 */
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
const wait = fadeMs > 0 ? fadeMs + 60 : 0
|
|
758
|
+
setTimeout(() => {
|
|
759
|
+
for (const node of dying) {
|
|
760
|
+
try {
|
|
761
|
+
node.source.onended = null
|
|
762
|
+
node.source.stop()
|
|
763
|
+
} catch {
|
|
764
|
+
/* 已经停了 */
|
|
765
|
+
}
|
|
766
|
+
try {
|
|
767
|
+
node.source.disconnect()
|
|
768
|
+
node.gain.disconnect()
|
|
769
|
+
} catch {
|
|
770
|
+
/* 同上 */
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}, wait)
|
|
774
|
+
playing = null
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function stop() {
|
|
778
|
+
token += 1
|
|
779
|
+
starting = false
|
|
780
|
+
if (playing !== null || live.size > 0) killAll(300)
|
|
781
|
+
idle()
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
async function play(track) {
|
|
785
|
+
const ac = ensure()
|
|
786
|
+
if (ac === null) return
|
|
787
|
+
const mine = ++token
|
|
788
|
+
starting = true
|
|
789
|
+
const data = await bytes(track.file)
|
|
790
|
+
if (mine !== token) {
|
|
791
|
+
starting = false
|
|
792
|
+
return
|
|
793
|
+
}
|
|
794
|
+
if (data === null) {
|
|
795
|
+
starting = false
|
|
796
|
+
if (active) setTimeout(() => next(), 400)
|
|
797
|
+
return
|
|
798
|
+
}
|
|
799
|
+
let buffer = null
|
|
800
|
+
try {
|
|
801
|
+
buffer = await ac.decodeAudioData(data.slice(0))
|
|
802
|
+
} catch {
|
|
803
|
+
buffer = null
|
|
804
|
+
}
|
|
805
|
+
if (mine !== token) {
|
|
806
|
+
starting = false
|
|
807
|
+
return
|
|
808
|
+
}
|
|
809
|
+
if (buffer === null) {
|
|
810
|
+
starting = false
|
|
811
|
+
if (active) setTimeout(() => next(), 400)
|
|
812
|
+
return
|
|
813
|
+
}
|
|
814
|
+
await unlock()
|
|
815
|
+
if (mine !== token) {
|
|
816
|
+
starting = false
|
|
817
|
+
return
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// 到这里才真正开声音:先清掉可能残留的其它音源,保证同时只有一路
|
|
821
|
+
killAll(0)
|
|
822
|
+
const gain = ac.createGain()
|
|
823
|
+
const source = ac.createBufferSource()
|
|
824
|
+
source.buffer = buffer
|
|
825
|
+
gain.gain.value = 0.0001
|
|
826
|
+
source.connect(gain)
|
|
827
|
+
gain.connect(master)
|
|
828
|
+
const node = { source, gain }
|
|
829
|
+
live.add(node)
|
|
830
|
+
playing = track.id
|
|
831
|
+
|
|
832
|
+
const started = ac.currentTime
|
|
833
|
+
const fade = Math.min(0.25, buffer.duration / 4)
|
|
834
|
+
try {
|
|
835
|
+
gain.gain.setValueAtTime(0.0001, started)
|
|
836
|
+
gain.gain.linearRampToValueAtTime(1, started + fade)
|
|
837
|
+
} catch {
|
|
838
|
+
gain.gain.value = 1
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
source.onended = () => {
|
|
842
|
+
live.delete(node)
|
|
843
|
+
try {
|
|
844
|
+
source.disconnect()
|
|
845
|
+
gain.disconnect()
|
|
846
|
+
} catch {
|
|
847
|
+
/* 已经断了 */
|
|
848
|
+
}
|
|
849
|
+
if (playing === track.id) playing = null
|
|
850
|
+
if (mine !== token) return
|
|
851
|
+
if (active) setTimeout(() => next(), 120)
|
|
852
|
+
else idle()
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
try {
|
|
856
|
+
source.start(0)
|
|
857
|
+
} catch {
|
|
858
|
+
live.delete(node)
|
|
859
|
+
playing = null
|
|
860
|
+
starting = false
|
|
861
|
+
return
|
|
862
|
+
}
|
|
863
|
+
starting = false
|
|
864
|
+
|
|
865
|
+
// 结尾先淡出,别硬切
|
|
866
|
+
const tail = Math.max(0, buffer.duration - Math.min(0.3, buffer.duration / 4))
|
|
867
|
+
setTimeout(() => {
|
|
868
|
+
if (mine !== token || !live.has(node)) return
|
|
869
|
+
try {
|
|
870
|
+
const now = ac.currentTime
|
|
871
|
+
gain.gain.cancelScheduledValues(now)
|
|
872
|
+
gain.gain.setValueAtTime(gain.gain.value, now)
|
|
873
|
+
gain.gain.linearRampToValueAtTime(0.0001, now + 0.26)
|
|
874
|
+
} catch {
|
|
875
|
+
/* 已经结束 */
|
|
876
|
+
}
|
|
877
|
+
}, Math.max(200, tail * 1000))
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
function next() {
|
|
881
|
+
if (!active || starting || playing !== null || live.size > 0) return
|
|
882
|
+
const track = pick()
|
|
883
|
+
if (track === null) return
|
|
884
|
+
play(track)
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function sync(want, list) {
|
|
888
|
+
const enabled = docSettings.musicEnabled !== false
|
|
889
|
+
const key = list.map((t) => t.id).join('|')
|
|
890
|
+
if (key !== poolKey) {
|
|
891
|
+
poolKey = key
|
|
892
|
+
bag = []
|
|
893
|
+
if (playing !== null && !list.some((t) => t.id === playing)) stop()
|
|
894
|
+
}
|
|
895
|
+
pool = list
|
|
896
|
+
const should = want && enabled && list.length > 0
|
|
897
|
+
if (!should) {
|
|
898
|
+
if (active) {
|
|
899
|
+
active = false
|
|
900
|
+
stop()
|
|
901
|
+
}
|
|
902
|
+
return
|
|
903
|
+
}
|
|
904
|
+
if (!active) {
|
|
905
|
+
// 新的一轮思考:洗牌袋、顺序游标、单曲认定全部重来
|
|
906
|
+
bag = []
|
|
907
|
+
seqIndex = 0
|
|
908
|
+
sessionTrack = null
|
|
909
|
+
}
|
|
910
|
+
active = true
|
|
911
|
+
if (playing === null && !starting && live.size === 0) next()
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
/** 巡检:paint 有可能漏掉「行没了」这一帧,这里兜住。 */
|
|
915
|
+
function tick(hasRow) {
|
|
916
|
+
if (!hasRow && active) {
|
|
917
|
+
active = false
|
|
918
|
+
stop()
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
function applyVolume() {
|
|
923
|
+
if (master === null || audio === null) return
|
|
924
|
+
const target = volumeGain()
|
|
925
|
+
try {
|
|
926
|
+
const now = audio.currentTime
|
|
927
|
+
// 取消排队中的自动化再线性过渡 80ms:拖滑轨时是立刻听出来的
|
|
928
|
+
master.gain.cancelScheduledValues(now)
|
|
929
|
+
master.gain.setValueAtTime(master.gain.value, now)
|
|
930
|
+
master.gain.linearRampToValueAtTime(target, now + 0.08)
|
|
931
|
+
} catch {
|
|
932
|
+
master.gain.value = target
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
function previewVolume(value) {
|
|
937
|
+
const n = Number(value)
|
|
938
|
+
if (!Number.isFinite(n)) return
|
|
939
|
+
docSettings = {
|
|
940
|
+
musicEnabled: docSettings.musicEnabled,
|
|
941
|
+
musicVolume: Math.max(0, Math.min(100, Math.round(n))),
|
|
942
|
+
musicMode: docSettings.musicMode,
|
|
943
|
+
}
|
|
944
|
+
applyVolume()
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
return { sync, tick, applyVolume, previewVolume, unlock, stop, state: () => ({ playing, live: live.size, active, starting }) }
|
|
948
|
+
})()
|
|
949
|
+
|
|
950
|
+
// 诊断:控制台里 __tsMusicState() 看引擎真实状态;顺带防止重复实例
|
|
951
|
+
if (typeof window !== 'undefined') {
|
|
952
|
+
window.__tsMusic = Music
|
|
953
|
+
window.__tsMusicState = () => Music.state()
|
|
954
|
+
}
|
|
955
|
+
|
|
580
956
|
function paint(root) {
|
|
581
957
|
if (pack === null) {
|
|
582
958
|
loadPack().then(() => paint(document))
|
|
@@ -592,21 +968,37 @@ window.__ModuleLoader__.load({
|
|
|
592
968
|
? pack.spinner
|
|
593
969
|
: null
|
|
594
970
|
|
|
971
|
+
let firstState = null
|
|
595
972
|
for (const row of rows) {
|
|
596
973
|
const state = stateOf(row)
|
|
597
974
|
if (state === null) continue
|
|
975
|
+
if (firstState === null) firstState = state
|
|
598
976
|
if (spinner !== null) swapSpinner(row, spinner)
|
|
599
977
|
else swapIcon(row, imageUrl(state.image.file))
|
|
600
978
|
const targets = swapCopy(row, state.text)
|
|
601
979
|
applyGradient(targets, pack.appearance)
|
|
602
980
|
}
|
|
603
981
|
tickSpinners(document)
|
|
982
|
+
// 行还在 = 正在思考,音乐跟着走;行消失就淡出
|
|
983
|
+
Music.sync(rows.length > 0, musicPoolOf(firstState))
|
|
604
984
|
}
|
|
605
985
|
|
|
606
986
|
/** Replace the in-memory pack after a save, then repaint. */
|
|
607
987
|
function adoptDocument(data) {
|
|
608
988
|
const packs = Array.isArray(data.packs) ? data.packs : []
|
|
609
989
|
pack = packs.find((entry) => entry.id === data.active) || packs[0] || null
|
|
990
|
+
if (data.settings !== undefined && data.settings !== null) {
|
|
991
|
+
docSettings = {
|
|
992
|
+
musicEnabled: data.settings.musicEnabled !== false,
|
|
993
|
+
musicVolume: Number.isFinite(Number(data.settings.musicVolume))
|
|
994
|
+
? Number(data.settings.musicVolume)
|
|
995
|
+
: 40,
|
|
996
|
+
musicMode: ['random', 'sequential', 'single'].includes(data.settings.musicMode)
|
|
997
|
+
? data.settings.musicMode
|
|
998
|
+
: 'random',
|
|
999
|
+
}
|
|
1000
|
+
Music.applyVolume()
|
|
1001
|
+
}
|
|
610
1002
|
paint(document)
|
|
611
1003
|
}
|
|
612
1004
|
|
|
@@ -944,6 +1336,9 @@ window.__ModuleLoader__.load({
|
|
|
944
1336
|
function SettingsPanel() {
|
|
945
1337
|
const [data, setData] = React.useState(null)
|
|
946
1338
|
const [selected, setSelected] = React.useState('')
|
|
1339
|
+
const [musicEnabled, setMusicEnabled] = React.useState(true)
|
|
1340
|
+
const [musicVolume, setMusicVolume] = React.useState(40)
|
|
1341
|
+
const [musicMode, setMusicMode] = React.useState('random')
|
|
947
1342
|
const [gradient, setGradient] = React.useState(DEFAULT_GRADIENT)
|
|
948
1343
|
const [gradientMode, setGradientMode] = React.useState('static')
|
|
949
1344
|
const [gradientSpeed, setGradientSpeed] = React.useState(3)
|
|
@@ -955,6 +1350,14 @@ window.__ModuleLoader__.load({
|
|
|
955
1350
|
const [draft, setDraft] = React.useState('')
|
|
956
1351
|
const [note, setNote] = React.useState('')
|
|
957
1352
|
const [newName, setNewName] = React.useState('')
|
|
1353
|
+
|
|
1354
|
+
React.useEffect(() => {
|
|
1355
|
+
const settings = data === null || data.settings === undefined ? null : data.settings
|
|
1356
|
+
if (settings === null || settings === null) return
|
|
1357
|
+
setMusicEnabled(settings.musicEnabled !== false)
|
|
1358
|
+
setMusicVolume(Number.isFinite(Number(settings.musicVolume)) ? Number(settings.musicVolume) : 40)
|
|
1359
|
+
setMusicMode(['random', 'sequential', 'single'].includes(settings.musicMode) ? settings.musicMode : 'random')
|
|
1360
|
+
}, [data])
|
|
958
1361
|
const [coverFile, setCoverFile] = React.useState(null)
|
|
959
1362
|
const [coverPreview, setCoverPreview] = React.useState('')
|
|
960
1363
|
const [seedFiles, setSeedFiles] = React.useState([])
|
|
@@ -972,7 +1375,7 @@ window.__ModuleLoader__.load({
|
|
|
972
1375
|
}
|
|
973
1376
|
})
|
|
974
1377
|
|
|
975
|
-
function adoptPack(entry) {
|
|
1378
|
+
function adoptPack(entry, keepDetail) {
|
|
976
1379
|
setSelected(entry.id)
|
|
977
1380
|
const appearance = entry.appearance === undefined ? {} : entry.appearance
|
|
978
1381
|
const colors = Array.isArray(appearance.gradient) ? appearance.gradient : []
|
|
@@ -988,10 +1391,11 @@ window.__ModuleLoader__.load({
|
|
|
988
1391
|
setSpinInterval(Number.isFinite(Number(spinner.interval)) ? Number(spinner.interval) : 165)
|
|
989
1392
|
setSpinPeriod(Number.isFinite(Number(spinner.period)) ? Number(spinner.period) : 2000)
|
|
990
1393
|
setSpinColor(typeof spinner.color === 'string' ? spinner.color : '')
|
|
991
|
-
|
|
1394
|
+
// 刷新数据时不该把用户正在看的详情页踢掉
|
|
1395
|
+
if (keepDetail !== true) setDetail(null)
|
|
992
1396
|
}
|
|
993
1397
|
|
|
994
|
-
function load(keepSelection) {
|
|
1398
|
+
function load(keepSelection, keepDetail) {
|
|
995
1399
|
const wanted = keepSelection === true ? selected : ''
|
|
996
1400
|
fetch(ROUTE + '/pack.json', { cache: 'no-store' })
|
|
997
1401
|
.then((response) => (response.ok ? response.json() : Promise.reject(new Error('HTTP ' + response.status))))
|
|
@@ -1001,7 +1405,7 @@ window.__ModuleLoader__.load({
|
|
|
1001
1405
|
const entry = packs.find((p) => p.id === wanted)
|
|
1002
1406
|
|| packs.find((p) => p.id === document.active)
|
|
1003
1407
|
|| packs[0]
|
|
1004
|
-
if (entry !== undefined) adoptPack(entry)
|
|
1408
|
+
if (entry !== undefined) adoptPack(entry, keepDetail)
|
|
1005
1409
|
if (packs.length === 0) setNote('还没有装任何套')
|
|
1006
1410
|
})
|
|
1007
1411
|
.catch((error) => setNote('读取失败:' + error.message))
|
|
@@ -1361,7 +1765,122 @@ window.__ModuleLoader__.load({
|
|
|
1361
1765
|
}
|
|
1362
1766
|
}
|
|
1363
1767
|
|
|
1364
|
-
|
|
1768
|
+
// ---- music pool ------------------------------------------------------
|
|
1769
|
+
|
|
1770
|
+
/** 把一首歌传进某个池:imageId 为空 = 这个套的通用音乐池。 */
|
|
1771
|
+
function uploadMusic(file, packId, imageId) {
|
|
1772
|
+
const query = '?pack=' + encodeURIComponent(packId)
|
|
1773
|
+
+ (imageId ? '&image=' + encodeURIComponent(imageId) : '')
|
|
1774
|
+
return fetch(ROUTE + '/music' + query, {
|
|
1775
|
+
method: 'POST',
|
|
1776
|
+
headers: {
|
|
1777
|
+
'content-type': 'application/octet-stream',
|
|
1778
|
+
'x-ts-name': encodeURIComponent(file.name),
|
|
1779
|
+
},
|
|
1780
|
+
body: file,
|
|
1781
|
+
}).then((response) => {
|
|
1782
|
+
if (!response.ok) throw new Error('music ' + response.status)
|
|
1783
|
+
return response.json()
|
|
1784
|
+
})
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
function removeMusic(packId, imageId, id) {
|
|
1788
|
+
return post(ROUTE + '/music-remove', { pack: packId, image: imageId || undefined, id })
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
function humanSize(bytes) {
|
|
1792
|
+
const n = Number(bytes) || 0
|
|
1793
|
+
if (n < 1024) return n + ' B'
|
|
1794
|
+
if (n < 1024 * 1024) return (n / 1024).toFixed(0) + ' KB'
|
|
1795
|
+
return (n / 1024 / 1024).toFixed(1) + ' MB'
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
/** 一个音乐池:导入、列表、删除。通用池和单图池共用这一个。 */
|
|
1799
|
+
function MusicPool({ packId, imageId, list, note, onChanged }) {
|
|
1800
|
+
const [busy, setBusy] = React.useState('')
|
|
1801
|
+
const tracks = Array.isArray(list) ? list : []
|
|
1802
|
+
|
|
1803
|
+
const add = (files) => {
|
|
1804
|
+
const picked = Array.from(files || [])
|
|
1805
|
+
if (picked.length === 0) return
|
|
1806
|
+
let failed = 0
|
|
1807
|
+
// 一首一首传:宿主那边是「读清单 → 追加 → 写回」,
|
|
1808
|
+
// 并发会把彼此的写入盖掉(三首只留下最后一首就是这么来的)
|
|
1809
|
+
const runAll = async () => {
|
|
1810
|
+
for (let i = 0; i < picked.length; i += 1) {
|
|
1811
|
+
setBusy('导入中… ' + (i + 1) + '/' + picked.length)
|
|
1812
|
+
try {
|
|
1813
|
+
await uploadMusic(picked[i], packId, imageId)
|
|
1814
|
+
} catch {
|
|
1815
|
+
failed += 1
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
setBusy(failed === 0 ? '' : '有 ' + failed + ' 首失败')
|
|
1819
|
+
onChanged()
|
|
1820
|
+
}
|
|
1821
|
+
runAll()
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// 一个框装一整池:内容多就往下长,长到 220px 之后自己滚
|
|
1825
|
+
const box = {
|
|
1826
|
+
border: '1px solid rgba(127,127,127,.28)',
|
|
1827
|
+
borderRadius: '10px',
|
|
1828
|
+
background: 'rgba(127,127,127,.05)',
|
|
1829
|
+
overflow: 'hidden',
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
|
|
1833
|
+
h('div', { style: S.row },
|
|
1834
|
+
h(FilePick, { label: '导入音乐', multiple: true, accept: 'audio/*', onFiles: add }),
|
|
1835
|
+
h('span', { style: S.hint }, tracks.length === 0 ? '空池' : tracks.length + ' 首'),
|
|
1836
|
+
busy === '' ? null : h('span', { style: S.hint }, busy),
|
|
1837
|
+
),
|
|
1838
|
+
|
|
1839
|
+
h('div', { style: box },
|
|
1840
|
+
tracks.length === 0
|
|
1841
|
+
? h('div', {
|
|
1842
|
+
style: { padding: '14px 14px', fontSize: '12px', opacity: 0.55, textAlign: 'center' },
|
|
1843
|
+
}, '还没有音乐。点上面「导入音乐」,可以多选。')
|
|
1844
|
+
: h('div', {
|
|
1845
|
+
style: { display: 'flex', flexDirection: 'column', maxHeight: '220px', overflowY: 'auto' },
|
|
1846
|
+
},
|
|
1847
|
+
tracks.map((track, i) => h('div', {
|
|
1848
|
+
key: track.id,
|
|
1849
|
+
style: {
|
|
1850
|
+
display: 'flex',
|
|
1851
|
+
alignItems: 'center',
|
|
1852
|
+
justifyContent: 'space-between',
|
|
1853
|
+
gap: '10px',
|
|
1854
|
+
padding: '7px 12px',
|
|
1855
|
+
fontSize: '12px',
|
|
1856
|
+
borderTop: i === 0 ? 'none' : '1px solid rgba(127,127,127,.16)',
|
|
1857
|
+
},
|
|
1858
|
+
},
|
|
1859
|
+
h('span', {
|
|
1860
|
+
style: {
|
|
1861
|
+
flex: 1,
|
|
1862
|
+
minWidth: 0,
|
|
1863
|
+
overflow: 'hidden',
|
|
1864
|
+
textOverflow: 'ellipsis',
|
|
1865
|
+
whiteSpace: 'nowrap',
|
|
1866
|
+
},
|
|
1867
|
+
}, track.name || track.id),
|
|
1868
|
+
h('span', { style: { opacity: 0.5, flex: 'none' } }, humanSize(track.size)),
|
|
1869
|
+
h('button', {
|
|
1870
|
+
type: 'button',
|
|
1871
|
+
style: { ...S.danger, flex: 'none' },
|
|
1872
|
+
onClick: () => {
|
|
1873
|
+
removeMusic(packId, imageId, track.id).then(onChanged).catch(() => {})
|
|
1874
|
+
},
|
|
1875
|
+
}, '删除'),
|
|
1876
|
+
)),
|
|
1877
|
+
),
|
|
1878
|
+
),
|
|
1879
|
+
|
|
1880
|
+
note === '' ? null : h('span', { style: S.hint }, note),
|
|
1881
|
+
)
|
|
1882
|
+
}
|
|
1883
|
+
function openGeneric() {
|
|
1365
1884
|
setNote('')
|
|
1366
1885
|
setDetail({ kind: 'generic' })
|
|
1367
1886
|
setDraft((current === undefined ? [] : current.fallbackTexts || []).join('\n'))
|
|
@@ -1387,6 +1906,12 @@ window.__ModuleLoader__.load({
|
|
|
1387
1906
|
commit({ pack: selected, image: { id: image.id, useFallback: image.useFallback === false } }, '')
|
|
1388
1907
|
}
|
|
1389
1908
|
|
|
1909
|
+
function toggleFallbackMusic(image) {
|
|
1910
|
+
if (image === undefined) return
|
|
1911
|
+
const next = image.useFallbackMusic === false
|
|
1912
|
+
commit({ pack: selected, image: { id: image.id, useFallbackMusic: next } }, '')
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1390
1915
|
// ---- detail view -------------------------------------------------------
|
|
1391
1916
|
|
|
1392
1917
|
if (detail !== null && detail.kind === 'import') {
|
|
@@ -1669,6 +2194,35 @@ window.__ModuleLoader__.load({
|
|
|
1669
2194
|
)
|
|
1670
2195
|
: null,
|
|
1671
2196
|
|
|
2197
|
+
h('div', null,
|
|
2198
|
+
h('span', { style: S.label },
|
|
2199
|
+
detail.kind === 'generic' ? '通用音乐池(这一套所有图共用)' : '这张图的音乐池'),
|
|
2200
|
+
h(MusicPool, {
|
|
2201
|
+
packId: selected,
|
|
2202
|
+
imageId: detail.kind === 'generic' ? '' : detail.id,
|
|
2203
|
+
list: detail.kind === 'generic'
|
|
2204
|
+
? (current === undefined ? null : current.fallbackMusic)
|
|
2205
|
+
: (detailImage === undefined ? null : detailImage.music),
|
|
2206
|
+
note: '',
|
|
2207
|
+
onChanged: () => load(true, true),
|
|
2208
|
+
}),
|
|
2209
|
+
detail.kind === 'generic'
|
|
2210
|
+
? null
|
|
2211
|
+
: h('div', { style: { ...S.row, justifyContent: 'space-between', marginTop: '4px' } },
|
|
2212
|
+
h('div', null,
|
|
2213
|
+
h('div', { style: { fontSize: '13px' } }, '也用通用音乐'),
|
|
2214
|
+
h('div', { style: S.hint }, '开启:和通用音乐池合在一起抽(默认);关闭:只放这张图自己的'),
|
|
2215
|
+
),
|
|
2216
|
+
h('div', {
|
|
2217
|
+
className: 'ts-switch',
|
|
2218
|
+
'data-on': detailImage !== undefined && detailImage.useFallbackMusic !== false ? '1' : '0',
|
|
2219
|
+
onClick: () => toggleFallbackMusic(detailImage),
|
|
2220
|
+
role: 'switch',
|
|
2221
|
+
'aria-checked': detailImage !== undefined && detailImage.useFallbackMusic !== false,
|
|
2222
|
+
}),
|
|
2223
|
+
),
|
|
2224
|
+
),
|
|
2225
|
+
|
|
1672
2226
|
h('div', null,
|
|
1673
2227
|
h('span', { style: S.label }, '一行一句;这张图会从这些句子里随机'),
|
|
1674
2228
|
h('textarea', {
|
|
@@ -1710,6 +2264,75 @@ window.__ModuleLoader__.load({
|
|
|
1710
2264
|
}, '主题:' + themeLabel),
|
|
1711
2265
|
),
|
|
1712
2266
|
|
|
2267
|
+
// 音乐:总开关 + 音量(照系统音量条那一排)
|
|
2268
|
+
h('div', null,
|
|
2269
|
+
h('span', { style: S.label }, '音乐'),
|
|
2270
|
+
h('div', {
|
|
2271
|
+
style: {
|
|
2272
|
+
display: 'flex', alignItems: 'center', gap: '12px',
|
|
2273
|
+
padding: '10px 14px', borderRadius: '10px',
|
|
2274
|
+
background: 'rgba(127,127,127,.07)',
|
|
2275
|
+
},
|
|
2276
|
+
},
|
|
2277
|
+
h('svg', {
|
|
2278
|
+
width: 18, height: 18, viewBox: '0 0 24 24', fill: 'none',
|
|
2279
|
+
stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round',
|
|
2280
|
+
strokeLinejoin: 'round', style: { opacity: musicEnabled ? 0.9 : 0.35, flex: 'none' },
|
|
2281
|
+
},
|
|
2282
|
+
h('path', { d: 'M4 9v6h3.5L12 19V5L7.5 9H4z' }),
|
|
2283
|
+
musicEnabled && musicVolume > 0 ? h('path', { d: 'M16 8.5a5 5 0 0 1 0 7' }) : null,
|
|
2284
|
+
musicEnabled && musicVolume > 50 ? h('path', { d: 'M18.6 6a8.5 8.5 0 0 1 0 12' }) : null,
|
|
2285
|
+
),
|
|
2286
|
+
h('input', {
|
|
2287
|
+
type: 'range', min: 0, max: 100, step: 1,
|
|
2288
|
+
value: musicVolume,
|
|
2289
|
+
disabled: !musicEnabled,
|
|
2290
|
+
style: { flex: 1, minWidth: 0, accentColor: '#4c8bf5' },
|
|
2291
|
+
onChange: (event) => {
|
|
2292
|
+
const next = Number(event.target.value)
|
|
2293
|
+
setMusicVolume(next)
|
|
2294
|
+
Music.previewVolume(next)
|
|
2295
|
+
},
|
|
2296
|
+
onPointerUp: () => commit({ musicVolume: musicVolume }, ''),
|
|
2297
|
+
onKeyUp: () => commit({ musicVolume: musicVolume }, ''),
|
|
2298
|
+
}),
|
|
2299
|
+
h('span', { style: { fontSize: '12px', opacity: 0.6, width: '34px', textAlign: 'right', flex: 'none' } },
|
|
2300
|
+
musicEnabled ? musicVolume + '%' : '关'),
|
|
2301
|
+
h('div', {
|
|
2302
|
+
className: 'ts-switch',
|
|
2303
|
+
'data-on': musicEnabled ? '1' : '0',
|
|
2304
|
+
role: 'switch',
|
|
2305
|
+
'aria-checked': musicEnabled,
|
|
2306
|
+
title: '思考时放音乐',
|
|
2307
|
+
onClick: () => commit({ musicEnabled: !musicEnabled }, ''),
|
|
2308
|
+
}),
|
|
2309
|
+
),
|
|
2310
|
+
h('div', { style: { ...S.row, gap: '8px', marginTop: '2px' } },
|
|
2311
|
+
h('span', { style: { ...S.hint, flex: 'none' } }, '这一轮怎么抽'),
|
|
2312
|
+
h('div', { style: { display: 'flex', gap: '6px' } },
|
|
2313
|
+
[['random', '随机'], ['sequential', '顺序'], ['single', '单曲循环']].map(([value, label]) => h('button', {
|
|
2314
|
+
key: value,
|
|
2315
|
+
type: 'button',
|
|
2316
|
+
className: 'ts-btn',
|
|
2317
|
+
style: {
|
|
2318
|
+
...S.btn,
|
|
2319
|
+
fontSize: '12px',
|
|
2320
|
+
padding: '4px 10px',
|
|
2321
|
+
borderColor: musicMode === value ? '#4c8bf5' : undefined,
|
|
2322
|
+
background: musicMode === value ? 'rgba(76,139,245,.14)' : undefined,
|
|
2323
|
+
},
|
|
2324
|
+
onClick: () => {
|
|
2325
|
+
setMusicMode(value)
|
|
2326
|
+
Music.stop()
|
|
2327
|
+
commit({ musicMode: value }, '')
|
|
2328
|
+
},
|
|
2329
|
+
}, label)),
|
|
2330
|
+
),
|
|
2331
|
+
),
|
|
2332
|
+
h('div', { style: S.hint },
|
|
2333
|
+
'只在「思考中」那一行出现时播放,行一消失就淡出。用哪几首在下面每张图 / 通用池里配。'),
|
|
2334
|
+
),
|
|
2335
|
+
|
|
1713
2336
|
// pack cards
|
|
1714
2337
|
h('div', null,
|
|
1715
2338
|
h('span', { style: S.label }, '套组'),
|
|
@@ -2092,6 +2715,14 @@ window.__ModuleLoader__.load({
|
|
|
2092
2715
|
// a missed mutation and lets the text rotate on a quiet row.
|
|
2093
2716
|
const interval = setInterval(() => {
|
|
2094
2717
|
paint(document)
|
|
2718
|
+
// paint 靠突变和这条心跳触发;行被整块拿走时补一刀,音乐没机会赖着不放
|
|
2719
|
+
let hasRow = false
|
|
2720
|
+
try {
|
|
2721
|
+
hasRow = document.querySelectorAll(ROW).length > 0
|
|
2722
|
+
} catch {
|
|
2723
|
+
hasRow = false
|
|
2724
|
+
}
|
|
2725
|
+
Music.tick(hasRow)
|
|
2095
2726
|
}, 1000)
|
|
2096
2727
|
// 字形每 80ms 一帧,1 秒的节拍会让它一顿一顿地跳,所以单独给一条快节拍。
|
|
2097
2728
|
// 只改文字和颜色,不做查询以外的重活。
|
package/index.js
CHANGED
|
@@ -40,6 +40,19 @@ const MAX_BODY = 1 << 20
|
|
|
40
40
|
const MAX_IMAGE = 32 * 1024 * 1024
|
|
41
41
|
/** 套组文件(含 base64 图片)可以有几十 MB。 */
|
|
42
42
|
const MAX_PACK_FILE = 192 * 1024 * 1024
|
|
43
|
+
/** 单个音乐文件的技术上限(不对外宣传,只是防止一次读爆内存)。 */
|
|
44
|
+
const MAX_MUSIC = 512 * 1024 * 1024
|
|
45
|
+
|
|
46
|
+
const MUSIC_MIME = {
|
|
47
|
+
'.mp3': 'audio/mpeg',
|
|
48
|
+
'.m4a': 'audio/mp4',
|
|
49
|
+
'.aac': 'audio/aac',
|
|
50
|
+
'.ogg': 'audio/ogg',
|
|
51
|
+
'.oga': 'audio/ogg',
|
|
52
|
+
'.opus': 'audio/ogg',
|
|
53
|
+
'.wav': 'audio/wav',
|
|
54
|
+
'.flac': 'audio/flac',
|
|
55
|
+
}
|
|
43
56
|
|
|
44
57
|
// ---------------------------------------------------------------- access gate
|
|
45
58
|
|
|
@@ -319,25 +332,59 @@ function cleanGradient(value) {
|
|
|
319
332
|
/** Mark built-in packs so the page never offers to rename or delete them. */
|
|
320
333
|
function decorate(document) {
|
|
321
334
|
const packs = Array.isArray(document.packs) ? document.packs : []
|
|
335
|
+
|
|
336
|
+
// 音乐总开关与音量存在文档根部,跟着套组一起走
|
|
337
|
+
if (document.settings === null || typeof document.settings !== 'object') document.settings = {}
|
|
338
|
+
if (typeof document.settings.musicEnabled !== 'boolean') document.settings.musicEnabled = true
|
|
339
|
+
const volume = Number(document.settings.musicVolume)
|
|
340
|
+
document.settings.musicVolume = Number.isFinite(volume) && volume >= 0 && volume <= 100
|
|
341
|
+
? Math.round(volume)
|
|
342
|
+
: 40
|
|
343
|
+
// 一轮里怎么选歌:随机 / 顺序 / 单曲循环
|
|
344
|
+
if (!['random', 'sequential', 'single'].includes(document.settings.musicMode)) {
|
|
345
|
+
document.settings.musicMode = 'random'
|
|
346
|
+
}
|
|
347
|
+
|
|
322
348
|
for (const pack of packs) {
|
|
323
349
|
if (typeof pack.builtin !== 'boolean') pack.builtin = BUILTIN.has(pack.id)
|
|
324
350
|
pack.slug = pack.id
|
|
351
|
+
if (!Array.isArray(pack.fallbackMusic)) pack.fallbackMusic = []
|
|
325
352
|
if (typeof pack.cover !== 'string' || pack.cover.length === 0) {
|
|
326
353
|
const first = Array.isArray(pack.images) ? pack.images[0] : undefined
|
|
327
354
|
pack.cover = first === undefined ? null : first.file
|
|
328
355
|
}
|
|
329
356
|
for (const image of Array.isArray(pack.images) ? pack.images : []) {
|
|
330
357
|
if (typeof image.useFallback !== 'boolean') image.useFallback = true
|
|
358
|
+
if (!Array.isArray(image.music)) image.music = []
|
|
359
|
+
if (typeof image.useFallbackMusic !== 'boolean') image.useFallbackMusic = true
|
|
331
360
|
}
|
|
332
361
|
}
|
|
333
362
|
return document
|
|
334
363
|
}
|
|
335
364
|
|
|
365
|
+
/** 内置套组自带的音乐:包里的文件,首次加载时复制进 storages。 */
|
|
366
|
+
const BUILTIN_MUSIC = {
|
|
367
|
+
'酒狐': ['朋友的酒 1.ogg', '朋友的酒 2.ogg', '朋友的酒 3.ogg'],
|
|
368
|
+
}
|
|
369
|
+
|
|
336
370
|
export const inject = ['webServer']
|
|
337
371
|
|
|
338
372
|
export function apply(ctx) {
|
|
339
373
|
const root = dataRoot()
|
|
340
374
|
|
|
375
|
+
/**
|
|
376
|
+
* 读-改-写的临界区。
|
|
377
|
+
*
|
|
378
|
+
* 一次多选导入会并发打到同一条路由,而每条都要 load → 改 → save;
|
|
379
|
+
* 不加锁的话后写的会把先写的覆盖掉(三个文件只留下最后一个)。
|
|
380
|
+
*/
|
|
381
|
+
let critical = Promise.resolve()
|
|
382
|
+
function lock(fn) {
|
|
383
|
+
const run = critical.then(fn, fn)
|
|
384
|
+
critical = run.then(() => {}, () => {})
|
|
385
|
+
return run
|
|
386
|
+
}
|
|
387
|
+
|
|
341
388
|
/** Read the document, or an empty skeleton when no pack is installed yet. */
|
|
342
389
|
async function load() {
|
|
343
390
|
try {
|
|
@@ -375,15 +422,20 @@ export function apply(ctx) {
|
|
|
375
422
|
return json(await load())
|
|
376
423
|
}
|
|
377
424
|
|
|
378
|
-
if (!relative.startsWith('/images/')) return notFound()
|
|
379
|
-
|
|
425
|
+
if (!relative.startsWith('/images/') && !relative.startsWith('/music/')) return notFound()
|
|
426
|
+
|
|
427
|
+
// 图片与音乐都在各自根目录下,按同样的「不许逃出根目录」规则解析
|
|
428
|
+
const music = relative.startsWith('/music/')
|
|
429
|
+
const base = music ? path.join(root, 'music') : path.join(root, 'images')
|
|
430
|
+
const file = resolveInside(base, relative.slice(music ? '/music/'.length : '/images/'.length))
|
|
380
431
|
if (file === null) return notFound()
|
|
381
432
|
|
|
382
433
|
try {
|
|
383
434
|
const bytes = await fs.readFile(file)
|
|
435
|
+
const table = music ? MUSIC_MIME : MIME
|
|
384
436
|
return new Response(bytes, {
|
|
385
437
|
headers: {
|
|
386
|
-
'content-type':
|
|
438
|
+
'content-type': table[path.extname(file).toLowerCase()] || 'application/octet-stream',
|
|
387
439
|
'cache-control': 'public, max-age=31536000, immutable',
|
|
388
440
|
'content-length': String(bytes.byteLength),
|
|
389
441
|
},
|
|
@@ -471,10 +523,27 @@ export function apply(ctx) {
|
|
|
471
523
|
if (typeof imagePatch.useFallback === 'boolean') {
|
|
472
524
|
image.useFallback = imagePatch.useFallback
|
|
473
525
|
}
|
|
526
|
+
if (typeof imagePatch.useFallbackMusic === 'boolean') {
|
|
527
|
+
image.useFallbackMusic = imagePatch.useFallbackMusic
|
|
528
|
+
}
|
|
474
529
|
}
|
|
475
530
|
}
|
|
476
531
|
}
|
|
477
532
|
|
|
533
|
+
// 音乐总开关与音量:文档根部,所有套组共用
|
|
534
|
+
const settings = document.settings
|
|
535
|
+
if (typeof patch.musicEnabled === 'boolean') settings.musicEnabled = patch.musicEnabled
|
|
536
|
+
if (patch.musicVolume !== undefined) {
|
|
537
|
+
const volume = Number(patch.musicVolume)
|
|
538
|
+
if (Number.isFinite(volume) && volume >= 0 && volume <= 100) {
|
|
539
|
+
settings.musicVolume = Math.round(volume)
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (typeof patch.musicMode === 'string'
|
|
543
|
+
&& ['random', 'sequential', 'single'].includes(patch.musicMode)) {
|
|
544
|
+
settings.musicMode = patch.musicMode
|
|
545
|
+
}
|
|
546
|
+
|
|
478
547
|
res.writeHead(200, {
|
|
479
548
|
'content-type': 'application/json; charset=utf-8',
|
|
480
549
|
'cache-control': 'no-store',
|
|
@@ -515,6 +584,18 @@ export function apply(ctx) {
|
|
|
515
584
|
document.active = document.packs.length > 0 ? document.packs[0].id : null
|
|
516
585
|
}
|
|
517
586
|
await fs.rm(path.join(root, 'images', id), { recursive: true, force: true })
|
|
587
|
+
// 这个套的音乐(通用池 + 每张图的池)一起清掉
|
|
588
|
+
await fs.rm(path.join(root, 'music', id), { recursive: true, force: true })
|
|
589
|
+
const musicRoot = path.join(root, 'music')
|
|
590
|
+
try {
|
|
591
|
+
for (const entry of await fs.readdir(musicRoot)) {
|
|
592
|
+
if (entry.startsWith(id + '-')) {
|
|
593
|
+
await fs.rm(path.join(musicRoot, entry), { recursive: true, force: true })
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
} catch {
|
|
597
|
+
/* music 目录还没建过就没什么可删 */
|
|
598
|
+
}
|
|
518
599
|
} else {
|
|
519
600
|
if (document.packs.some((p) => p.id === id)) return fail(409, '这个套名已经有了')
|
|
520
601
|
document.packs.push({
|
|
@@ -623,6 +704,180 @@ export function apply(ctx) {
|
|
|
623
704
|
|
|
624
705
|
ctx.effect(() => disposeUpload)
|
|
625
706
|
|
|
707
|
+
/** Find a pack, and inside it either the pack-level pool or one image's pool. */
|
|
708
|
+
function musicBucket(document, packId, imageId) {
|
|
709
|
+
const pack = document.packs.find((p) => p.id === packId)
|
|
710
|
+
if (pack === undefined) return null
|
|
711
|
+
if (imageId === null || imageId === undefined || imageId === '') {
|
|
712
|
+
if (!Array.isArray(pack.fallbackMusic)) pack.fallbackMusic = []
|
|
713
|
+
return { list: pack.fallbackMusic, dir: packId, holder: pack, key: 'fallbackMusic' }
|
|
714
|
+
}
|
|
715
|
+
const image = (Array.isArray(pack.images) ? pack.images : []).find((i) => i.id === imageId)
|
|
716
|
+
if (image === undefined) return null
|
|
717
|
+
if (!Array.isArray(image.music)) image.music = []
|
|
718
|
+
return { list: image.music, dir: packId + '-' + imageId, holder: image, key: 'music' }
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* 音乐导入:原始字节,套组/图片由查询参数指定,文件名走 x-ts-name。
|
|
723
|
+
* 音频复制进 storages,套组导出时再原样带出去 —— 和图片一个规矩。
|
|
724
|
+
*/
|
|
725
|
+
const disposeMusicUp = ctx.webServer.register({
|
|
726
|
+
kind: 'exact',
|
|
727
|
+
path: ROUTE + '/music',
|
|
728
|
+
async handler(req, res) {
|
|
729
|
+
const fail = (status, message) => {
|
|
730
|
+
res.writeHead(status, { 'content-type': 'text/plain; charset=utf-8' })
|
|
731
|
+
res.end(message)
|
|
732
|
+
}
|
|
733
|
+
if (!originAllowed((name) => req.headers[name])) return fail(403, 'forbidden')
|
|
734
|
+
if (req.method !== 'POST') return fail(405, 'method not allowed')
|
|
735
|
+
try {
|
|
736
|
+
const url = new URL(req.url, 'http://local')
|
|
737
|
+
const packId = url.searchParams.get('pack')
|
|
738
|
+
const imageId = url.searchParams.get('image')
|
|
739
|
+
const rawName = req.headers['x-ts-name']
|
|
740
|
+
if (!packId || !rawName) return fail(400, 'need ?pack= and x-ts-name')
|
|
741
|
+
|
|
742
|
+
let name
|
|
743
|
+
try {
|
|
744
|
+
name = decodeURIComponent(String(rawName))
|
|
745
|
+
} catch {
|
|
746
|
+
return fail(400, 'bad x-ts-name')
|
|
747
|
+
}
|
|
748
|
+
const ext = path.extname(name).toLowerCase()
|
|
749
|
+
if (!Object.prototype.hasOwnProperty.call(MUSIC_MIME, ext)) {
|
|
750
|
+
return fail(415, 'unsupported audio type: ' + ext)
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
const body = await readBody(req, MAX_MUSIC)
|
|
754
|
+
if (body.length === 0) return fail(400, 'empty body')
|
|
755
|
+
|
|
756
|
+
// 整个「读文档 → 落盘 → 写清单」都在锁里:多选导入是并发请求,
|
|
757
|
+
// 不加锁时后一次 save 会用旧文档把前一次的结果覆盖掉
|
|
758
|
+
const result = await lock(async () => {
|
|
759
|
+
const document = await load()
|
|
760
|
+
const bucket = musicBucket(document, packId, imageId)
|
|
761
|
+
if (bucket === null) return { status: 404, message: '没有这个套或这张图' }
|
|
762
|
+
|
|
763
|
+
const dir = path.join(root, 'music', bucket.dir)
|
|
764
|
+
await fs.mkdir(dir, { recursive: true })
|
|
765
|
+
const file = 'm-' + Date.now().toString(36) + '-' + Math.floor(Math.random() * 1e6) + ext
|
|
766
|
+
const absolute = path.join(dir, file)
|
|
767
|
+
await fs.writeFile(absolute, body)
|
|
768
|
+
|
|
769
|
+
bucket.list.push({
|
|
770
|
+
id: file.slice(0, -ext.length),
|
|
771
|
+
file: bucket.dir + '/' + file,
|
|
772
|
+
name: path.basename(name, ext),
|
|
773
|
+
size: body.length,
|
|
774
|
+
})
|
|
775
|
+
try {
|
|
776
|
+
await save(document)
|
|
777
|
+
} catch (error) {
|
|
778
|
+
// 字节落盘了但清单没写进去:把文件收回来,别留下没人认领的音频
|
|
779
|
+
await fs.unlink(absolute).catch(() => {})
|
|
780
|
+
throw error
|
|
781
|
+
}
|
|
782
|
+
return { status: 200, added: bucket.dir + '/' + file }
|
|
783
|
+
})
|
|
784
|
+
|
|
785
|
+
if (result.status !== 200) return fail(result.status, result.message)
|
|
786
|
+
res.writeHead(200, {
|
|
787
|
+
'content-type': 'application/json; charset=utf-8',
|
|
788
|
+
'cache-control': 'no-store',
|
|
789
|
+
})
|
|
790
|
+
res.end(JSON.stringify({ ok: true, added: result.added, pack: packId }))
|
|
791
|
+
} catch (error) {
|
|
792
|
+
fail(400, String((error && error.message) || error))
|
|
793
|
+
}
|
|
794
|
+
},
|
|
795
|
+
})
|
|
796
|
+
|
|
797
|
+
ctx.effect(() => disposeMusicUp)
|
|
798
|
+
|
|
799
|
+
/** 删掉音乐池里的一首(同时删盘上的文件)。 */
|
|
800
|
+
const disposeMusicDel = ctx.webServer.register({
|
|
801
|
+
kind: 'exact',
|
|
802
|
+
path: ROUTE + '/music-remove',
|
|
803
|
+
async handler(req, res) {
|
|
804
|
+
const fail = (status, message) => {
|
|
805
|
+
res.writeHead(status, { 'content-type': 'text/plain; charset=utf-8' })
|
|
806
|
+
res.end(message)
|
|
807
|
+
}
|
|
808
|
+
if (!originAllowed((name) => req.headers[name])) return fail(403, 'forbidden')
|
|
809
|
+
if (req.method !== 'POST') return fail(405, 'method not allowed')
|
|
810
|
+
try {
|
|
811
|
+
const body = JSON.parse((await readBody(req, MAX_BODY)).toString('utf8'))
|
|
812
|
+
const outcome = await lock(async () => {
|
|
813
|
+
const document = await load()
|
|
814
|
+
const bucket = musicBucket(document, String(body.pack || ''), body.image)
|
|
815
|
+
if (bucket === null) return { status: 404, message: '没有这个套或这张图' }
|
|
816
|
+
const index = bucket.list.findIndex((m) => m.id === body.id)
|
|
817
|
+
if (index < 0) return { status: 404, message: '没有这首' }
|
|
818
|
+
const entry = bucket.list.splice(index, 1)[0]
|
|
819
|
+
await save(document)
|
|
820
|
+
return { status: 200, file: entry.file }
|
|
821
|
+
})
|
|
822
|
+
if (outcome.status !== 200) return fail(outcome.status, outcome.message)
|
|
823
|
+
await fs.unlink(path.join(root, 'music', outcome.file.replace('/', path.sep))).catch(() => {})
|
|
824
|
+
res.writeHead(200, {
|
|
825
|
+
'content-type': 'application/json; charset=utf-8',
|
|
826
|
+
'cache-control': 'no-store',
|
|
827
|
+
})
|
|
828
|
+
res.end(JSON.stringify({ ok: true }))
|
|
829
|
+
} catch (error) {
|
|
830
|
+
fail(400, String((error && error.message) || error))
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
})
|
|
834
|
+
ctx.effect(() => disposeMusicDel)
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* 把内置套组自带的音乐铺进 storages。
|
|
838
|
+
*
|
|
839
|
+
* 只在缺的时候复制:用户删掉的不会被硬塞回来这件事要另说 —— 目前按文件名判断,
|
|
840
|
+
* 删掉后下次启动会重新出现,内置资源就该这样。
|
|
841
|
+
*/
|
|
842
|
+
async function seedBuiltinMusic() {
|
|
843
|
+
let touched = false
|
|
844
|
+
try {
|
|
845
|
+
const document = await load()
|
|
846
|
+
for (const [packId, files] of Object.entries(BUILTIN_MUSIC)) {
|
|
847
|
+
const pack = document.packs.find((p) => p.id === packId)
|
|
848
|
+
if (pack === undefined) continue
|
|
849
|
+
if (!Array.isArray(pack.fallbackMusic)) pack.fallbackMusic = []
|
|
850
|
+
for (const [order, name] of files.entries()) {
|
|
851
|
+
const label = name.replace(/\.[^.]+$/, '')
|
|
852
|
+
if (pack.fallbackMusic.some((m) => m.name === label)) continue
|
|
853
|
+
let bytes = null
|
|
854
|
+
try {
|
|
855
|
+
bytes = await fs.readFile(new URL('./assets/music/' + packId + '/' + name, import.meta.url))
|
|
856
|
+
} catch {
|
|
857
|
+
continue
|
|
858
|
+
}
|
|
859
|
+
const dir = path.join(root, 'music', packId)
|
|
860
|
+
await fs.mkdir(dir, { recursive: true })
|
|
861
|
+
const file = 'builtin-' + String(order + 1) + path.extname(name)
|
|
862
|
+
await fs.writeFile(path.join(dir, file), bytes)
|
|
863
|
+
pack.fallbackMusic.push({
|
|
864
|
+
id: file.replace(/\.[^.]+$/, ''),
|
|
865
|
+
file: packId + '/' + file,
|
|
866
|
+
name: label,
|
|
867
|
+
size: bytes.length,
|
|
868
|
+
builtin: true,
|
|
869
|
+
})
|
|
870
|
+
touched = true
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (touched) await save(document)
|
|
874
|
+
} catch {
|
|
875
|
+
/* 内置音乐是可选的,铺不进去也不该影响插件启动 */
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
seedBuiltinMusic()
|
|
880
|
+
|
|
626
881
|
/**
|
|
627
882
|
* Export one pack as a self-contained JSON document.
|
|
628
883
|
*
|
|
@@ -645,10 +900,29 @@ export function apply(ctx) {
|
|
|
645
900
|
const pack = data.packs.find((p) => p.id === body.pack)
|
|
646
901
|
if (pack === undefined) return fail(404, '没有这个套')
|
|
647
902
|
|
|
648
|
-
// zip: pack.json + images/<name
|
|
903
|
+
// zip: pack.json + images/<name> + music/<name>,二进制原样搬
|
|
649
904
|
const entries = []
|
|
650
905
|
const images = []
|
|
651
906
|
let index = 0
|
|
907
|
+
|
|
908
|
+
/** 把一首歌读出来塞进 zip,返回清单里那一条。 */
|
|
909
|
+
let musicIndex = 0
|
|
910
|
+
async function packMusicEntry(entry) {
|
|
911
|
+
const file = path.join(root, 'music', String(entry.file || '').replace('/', path.sep))
|
|
912
|
+
let bytes = null
|
|
913
|
+
try {
|
|
914
|
+
bytes = await fs.readFile(file)
|
|
915
|
+
} catch {
|
|
916
|
+
bytes = null
|
|
917
|
+
}
|
|
918
|
+
if (bytes === null) return null
|
|
919
|
+
musicIndex += 1
|
|
920
|
+
const ext = path.extname(entry.file).toLowerCase() || '.mp3'
|
|
921
|
+
const name = 'music/m' + String(musicIndex).padStart(3, '0') + ext
|
|
922
|
+
entries.push({ name, data: bytes })
|
|
923
|
+
return { file: name, name: entry.name, size: bytes.length }
|
|
924
|
+
}
|
|
925
|
+
|
|
652
926
|
for (const image of pack.images) {
|
|
653
927
|
const file = path.join(root, 'images', image.file.replace('/', path.sep))
|
|
654
928
|
let bytes = null
|
|
@@ -662,29 +936,49 @@ export function apply(ctx) {
|
|
|
662
936
|
const ext = path.extname(image.file).toLowerCase() || '.gif'
|
|
663
937
|
const name = 'images/i' + String(index).padStart(3, '0') + ext
|
|
664
938
|
entries.push({ name, data: bytes })
|
|
939
|
+
|
|
940
|
+
const trackList = []
|
|
941
|
+
for (const track of Array.isArray(image.music) ? image.music : []) {
|
|
942
|
+
const packed = await packMusicEntry(track)
|
|
943
|
+
if (packed !== null) trackList.push(packed)
|
|
944
|
+
}
|
|
945
|
+
|
|
665
946
|
images.push({
|
|
666
947
|
id: image.id,
|
|
667
948
|
name: image.name,
|
|
668
949
|
texts: Array.isArray(image.texts) ? image.texts : [],
|
|
669
950
|
useFallback: image.useFallback !== false,
|
|
951
|
+
useFallbackMusic: image.useFallbackMusic !== false,
|
|
952
|
+
music: trackList,
|
|
670
953
|
file: name,
|
|
671
954
|
sourceFile: image.file,
|
|
672
955
|
})
|
|
673
956
|
}
|
|
674
957
|
|
|
958
|
+
const packMusic = []
|
|
959
|
+
for (const track of Array.isArray(pack.fallbackMusic) ? pack.fallbackMusic : []) {
|
|
960
|
+
const packed = await packMusicEntry(track)
|
|
961
|
+
if (packed !== null) packMusic.push(packed)
|
|
962
|
+
}
|
|
963
|
+
|
|
675
964
|
const manifest = {
|
|
676
965
|
format: 'dsh-think-skin/pack',
|
|
677
|
-
version:
|
|
966
|
+
version: 3,
|
|
678
967
|
exportedAt: new Date().toISOString(),
|
|
679
968
|
pack: {
|
|
680
969
|
id: pack.id,
|
|
681
970
|
name: pack.name,
|
|
682
971
|
appearance: pack.appearance || {},
|
|
683
972
|
fallbackTexts: Array.isArray(pack.fallbackTexts) ? pack.fallbackTexts : [],
|
|
973
|
+
fallbackMusic: packMusic,
|
|
684
974
|
spinner: pack.spinner === undefined ? null : pack.spinner,
|
|
685
975
|
cover: (images.find((i) => i.sourceFile === pack.cover) || images[0] || {}).file || null,
|
|
686
976
|
images,
|
|
687
977
|
},
|
|
978
|
+
settings: {
|
|
979
|
+
musicEnabled: data.settings.musicEnabled,
|
|
980
|
+
musicVolume: data.settings.musicVolume,
|
|
981
|
+
},
|
|
688
982
|
}
|
|
689
983
|
entries.unshift({ name: 'pack.json', data: Buffer.from(JSON.stringify(manifest, null, 1), 'utf8') })
|
|
690
984
|
|
|
@@ -861,6 +1155,52 @@ export function apply(ctx) {
|
|
|
861
1155
|
}
|
|
862
1156
|
if (cover === null) cover = stored[0].file
|
|
863
1157
|
|
|
1158
|
+
// 音乐:清单里记的路径都在 zip 的 music/ 下,原样搬进 storages
|
|
1159
|
+
const musicRoot = path.join(root, 'music', id)
|
|
1160
|
+
async function importTrack(track) {
|
|
1161
|
+
if (track === null || typeof track !== 'object') return null
|
|
1162
|
+
const raw = typeof track.file === 'string' ? track.file : ''
|
|
1163
|
+
if (raw === '') return null
|
|
1164
|
+
const base = path.basename(raw)
|
|
1165
|
+
const ext = path.extname(base).toLowerCase()
|
|
1166
|
+
if (!Object.prototype.hasOwnProperty.call(MUSIC_MIME, ext)) return null
|
|
1167
|
+
let bytes = null
|
|
1168
|
+
if (zipFiles !== null && zipFiles.get(raw) !== undefined) bytes = zipFiles.get(raw)
|
|
1169
|
+
else if (zipFiles !== null && zipFiles.get(base) !== undefined) bytes = zipFiles.get(base)
|
|
1170
|
+
if (bytes === undefined || bytes === null) return null
|
|
1171
|
+
await fs.mkdir(musicRoot, { recursive: true })
|
|
1172
|
+
const file = 'imp-' + Date.now().toString(36) + '-' + Math.floor(Math.random() * 1e6) + ext
|
|
1173
|
+
await fs.writeFile(path.join(musicRoot, file), bytes)
|
|
1174
|
+
return {
|
|
1175
|
+
id: file.slice(0, -ext.length),
|
|
1176
|
+
file: id + '/' + file,
|
|
1177
|
+
name: typeof track.name === 'string' ? track.name : path.basename(base, ext),
|
|
1178
|
+
size: bytes.length,
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
const importedFallbackMusic = []
|
|
1183
|
+
for (const track of Array.isArray(source.fallbackMusic) ? source.fallbackMusic : []) {
|
|
1184
|
+
const got = await importTrack(track)
|
|
1185
|
+
if (got !== null) importedFallbackMusic.push(got)
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
// 每张图自己的音乐池:用导出时的文件名对齐(stored 会跳过无效图片)
|
|
1189
|
+
const sourceImages = Array.isArray(source.images) ? source.images : []
|
|
1190
|
+
let cursor = 0
|
|
1191
|
+
for (const item of stored) {
|
|
1192
|
+
if (cursor >= sourceImages.length) break
|
|
1193
|
+
const record = sourceImages[cursor]
|
|
1194
|
+
cursor += 1
|
|
1195
|
+
const list = []
|
|
1196
|
+
for (const track of Array.isArray(record.music) ? record.music : []) {
|
|
1197
|
+
const got = await importTrack(track)
|
|
1198
|
+
if (got !== null) list.push(got)
|
|
1199
|
+
}
|
|
1200
|
+
if (list.length > 0) item.music = list
|
|
1201
|
+
item.useFallbackMusic = record.useFallbackMusic !== false
|
|
1202
|
+
}
|
|
1203
|
+
|
|
864
1204
|
data.packs.push({
|
|
865
1205
|
id,
|
|
866
1206
|
name: id,
|
|
@@ -875,6 +1215,7 @@ export function apply(ctx) {
|
|
|
875
1215
|
spinner: source.spinner !== null && typeof source.spinner === 'object'
|
|
876
1216
|
? source.spinner
|
|
877
1217
|
: null,
|
|
1218
|
+
fallbackMusic: importedFallbackMusic,
|
|
878
1219
|
images: stored,
|
|
879
1220
|
})
|
|
880
1221
|
if (!data.active) data.active = id
|
|
@@ -889,6 +1230,7 @@ export function apply(ctx) {
|
|
|
889
1230
|
res.end(payload)
|
|
890
1231
|
} catch (error) {
|
|
891
1232
|
if (dir !== null) await fs.rm(dir, { recursive: true, force: true }).catch(() => {})
|
|
1233
|
+
await fs.rm(path.join(root, 'music', String(id || '')), { recursive: true, force: true }).catch(() => {})
|
|
892
1234
|
fail(400, String((error && error.message) || error))
|
|
893
1235
|
}
|
|
894
1236
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-think-skin",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "把 DSH 的思考状态行换成你自己的图、自己的话:每张图带自己的文案池,逐字打出、高光扫过、渐变可调。支持套组导入导出与字符转圈。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"assets/酒狐",
|
|
42
42
|
"tools/compile-pack.py",
|
|
43
43
|
"assets/texts",
|
|
44
|
+
"assets/music",
|
|
44
45
|
"tools/export-texts.py",
|
|
45
46
|
"locale"
|
|
46
47
|
],
|