Skip to content

Commit ea5ff3f

Browse files
committed
Surge-Module-Manager(fix):修改本地模块不生效
1 parent 6202c17 commit ea5ff3f

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

Surge-Module-Manager/components/HomeView.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,18 @@ export function HomeView() {
235235
if (merged.name && merged.name !== target.name) {
236236
await renameModuleFile(target, merged.name)
237237
}
238-
await updateModuleMetadata(merged, {
239-
link: merged.link,
240-
category: merged.category,
241-
})
238+
if (merged.isLocal || !merged.link) {
239+
await saveLocalModule(
240+
{ ...merged, saveDir: inferSaveDir(merged) },
241+
merged.content ?? ""
242+
)
243+
} else {
244+
await updateModuleMetadata(merged, {
245+
link: merged.link,
246+
category: merged.category,
247+
local: false,
248+
})
249+
}
242250
await refreshModules()
243251
setStage("修改完成")
244252
} catch (e: any) {

Surge-Module-Manager/utils/storage.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,20 @@ function upsertLink(content: string, prefixes: string[], value?: string): string
239239
return `${prefix}${trimmed}\n${filtered.join("\n")}`
240240
}
241241

242-
export async function updateModuleMetadata(target: ModuleInfo | string, info: { link?: string; category?: string }) {
242+
export async function updateModuleMetadata(
243+
target: ModuleInfo | string,
244+
info: { link?: string; category?: string; local?: boolean }
245+
) {
243246
const fm = fmOrThrow()
244247
const path = resolveModulePath(target)
245248
if (!(await exists(path))) return
246249
const raw = await fm.readAsString(path)
247250
let content = String(raw ?? "")
248251
content = upsertLink(content, getLinkPrefixes(), info.link)
249252
content = upsertTag(content, "category", info.category)
253+
if (info.local !== undefined) {
254+
content = upsertTag(content, "local", info.local ? "true" : "")
255+
}
250256
await fm.writeAsString(path, content)
251257
}
252258

0 commit comments

Comments
 (0)