Skip to content

Commit ec8ac78

Browse files
authored
Merge branch 'master' into master
2 parents 2161d96 + 41bced5 commit ec8ac78

File tree

23 files changed

+1004
-310
lines changed

23 files changed

+1004
-310
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
"@webext-core/job-scheduler": "^1.0.0",
4747
"@webext-core/messaging": "^2.3.0",
4848
"@webext-core/storage": "^1.2.0",
49-
"axios": "^1.13.6",
49+
"axios": "^1.14.0",
5050
"crypto-js": "^4.2.0",
5151
"date-fns": "^4.1.0",
5252
"echarts": "^6.0.0",
5353
"es-toolkit": "^1.45.1",
5454
"file-saver": "^2.0.5",
55-
"filesize": "^11.0.14",
55+
"filesize": "^11.0.15",
5656
"idb": "^8.0.3",
5757
"jszip": "^3.10.1",
5858
"konva": "^10.2.3",
@@ -93,7 +93,7 @@
9393
"tsx": "^4.21.0",
9494
"typescript": "~6.0.2",
9595
"vite": "^6.4.1",
96-
"vite-plugin-node-polyfills": "^0.25.0",
96+
"vite-plugin-node-polyfills": "^0.26.0",
9797
"vite-plugin-vue-devtools": "^8.1.1",
9898
"vite-plugin-vuetify": "^2.1.3",
9999
"vite-plugin-web-extension": "4.5.0",

pnpm-lock.yaml

Lines changed: 22 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/entries/options/stores/metadata.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,26 +337,34 @@ export const useMetadataStore = defineStore("metadata", {
337337
await this.$save();
338338
},
339339

340-
async addSite(siteId: TSiteID, siteConfig: ISiteUserConfig) {
340+
async addSite(siteId: TSiteID, siteConfig: ISiteUserConfig, options?: { reBuildMap?: boolean }) {
341+
const { reBuildMap = true } = options ?? {};
342+
341343
delete siteConfig.valid;
342344
this.sites[siteId] = siteConfig;
343-
await this.buildSiteHostMap();
344-
await this.buildSiteNameMap();
345+
346+
if (reBuildMap) {
347+
await this.buildSiteMapCache(false);
348+
}
349+
345350
await this.$save();
346351
},
347352

348-
async removeSite(siteId: TSiteID) {
353+
async removeSite(siteId: TSiteID, options?: { reBuildMap?: boolean }) {
354+
const { reBuildMap = true } = options ?? {};
355+
349356
delete this.sites[siteId];
350-
await this.buildSiteHostMap();
351-
await this.buildSiteNameMap();
357+
358+
if (reBuildMap) {
359+
await this.buildSiteMapCache(false);
360+
}
361+
352362
await this.$save();
353363
},
354364

355365
/**
356366
* 在添加、编辑站点时调用,重新生成 host 对站点的映射,
357367
* 便于 content-script 等其他地方通过 (await extStorage.getItem('metadata')).siteHostMap[host] 获取站点 ID
358-
*
359-
* Note: 对于在本commit之前就安装了插件的站点,需要重新编辑站点配置一次才能生成该映射
360368
*/
361369
async buildSiteHostMap() {
362370
const siteHostMap: Record<TSiteHost, TSiteID> = {};
@@ -389,6 +397,15 @@ export const useMetadataStore = defineStore("metadata", {
389397
this.siteNameMap = siteNameMap;
390398
},
391399

400+
async buildSiteMapCache(save: boolean = false) {
401+
await this.buildSiteNameMap();
402+
await this.buildSiteHostMap();
403+
404+
if (save) {
405+
await this.$save();
406+
}
407+
},
408+
392409
async addSearchSolution(solution: ISearchSolutionMetadata) {
393410
this.solutions[solution.id] = solution;
394411
await this.$save();

src/entries/options/views/Settings/SetBackup/EditDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function editClientConfig() {
4141
</v-card-title>
4242
<v-divider />
4343
<v-card-text>
44-
<Editor v-model="clientConfig" />
44+
<Editor v-if="clientConfig" v-model="clientConfig" />
4545
</v-card-text>
4646
<v-divider />
4747
<v-card-actions>

src/entries/options/views/Settings/SetBackup/Editor.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ const emits = defineEmits<{
1717
}>();
1818
1919
const clientMeta = computedAsync<IBackupMetadata<any>>(
20-
async () => await getBackupServerMetaData(clientConfig.value!.type),
21-
{} as IBackupMetadata<any>,
20+
async () => {
21+
const clientType = clientConfig.value?.type;
22+
if (!clientType) {
23+
return { requiredField: [] } as IBackupMetadata<any>;
24+
}
25+
return await getBackupServerMetaData(clientType);
26+
},
27+
{ requiredField: [] } as IBackupMetadata<any>,
2228
);
2329
2430
const formValid = ref<boolean>(false);
2531
2632
async function checkConnect() {
27-
if (formValid) {
28-
const client = await getBackupServer(clientConfig.value!);
33+
const clientType = clientConfig.value?.type;
34+
if (formValid.value && clientConfig.value && clientType) {
35+
const client = await getBackupServer(clientConfig.value);
2936
return await client.ping();
3037
}
3138
return false;

src/entries/options/views/Settings/SetSite/EditDialog.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ const isFormValid = ref<boolean>(false);
2020
const storedSiteUserConfig = ref<ISiteUserConfig & { valid?: boolean }>({ valid: false });
2121
provide("storedSiteUserConfig", storedSiteUserConfig);
2222
23-
function patchSite() {
24-
metadataStore.addSite(props.siteId, storedSiteUserConfig.value);
25-
metadataStore.$save();
23+
async function patchSite() {
24+
await metadataStore.addSite(props.siteId, storedSiteUserConfig.value);
2625
showDialog.value = false;
2726
}
2827

src/entries/options/views/Settings/SetSite/Index.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import AddDialog from "./AddDialog.vue";
1414
import EditDialog from "./EditDialog.vue";
1515
import EditSearchEntryList from "./EditSearchEntryList.vue";
1616
import OneClickImportDialog from "./OneClickImportDialog.vue";
17+
import RebuildMapDialog from "./RebuildMapDialog.vue";
1718
import SiteFavicon from "@/options/components/SiteFavicon/Index.vue";
1819
import DeleteDialog from "@/options/components/DeleteDialog.vue";
1920
import NavButton from "@/options/components/NavButton.vue";
2021
21-
import { allAddedSiteInfo, type ISiteTableItem } from "@/options/views/Settings/SetSite/utils.ts"; // <-- 数据来源
22+
// 数据来源
23+
import { allAddedSiteInfo, type ISiteTableItem } from "./utils.ts";
2224
2325
const { t } = useI18n();
2426
@@ -30,6 +32,7 @@ const showAddDialog = ref<boolean>(false);
3032
const showEditDialog = ref<boolean>(false);
3133
const showDeleteDialog = ref<boolean>(false);
3234
const showOneClickImportDialog = ref<boolean>(false);
35+
const showRebuildMapDialog = ref<boolean>(false);
3336
3437
const tableHeader = computed(() => {
3538
const baseHeaders = [
@@ -146,6 +149,13 @@ async function flushSiteFavicon(siteId: TSiteID | TSiteID[]) {
146149
@click="() => flushSiteFavicon(tableSelected)"
147150
/>
148151

152+
<NavButton
153+
:text="t('SetSite.index.reBuildMap')"
154+
color="indigo"
155+
icon="mdi-wrench"
156+
@click="showRebuildMapDialog = true"
157+
/>
158+
149159
<v-spacer />
150160
<v-text-field
151161
v-model="tableWaitFilterRef"
@@ -343,6 +353,7 @@ async function flushSiteFavicon(siteId: TSiteID | TSiteID[]) {
343353
<DeleteDialog v-model="showDeleteDialog" :to-delete-ids="toDeleteIds" :confirm-delete="confirmDeleteSite" />
344354
<EditDialog v-model="showEditDialog" :site-id="toEditId!" />
345355
<OneClickImportDialog v-model="showOneClickImportDialog" />
356+
<RebuildMapDialog v-model="showRebuildMapDialog" />
346357
</template>
347358

348359
<style scoped lang="scss"></style>

src/entries/options/views/Settings/SetSite/OneClickImportDialog.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function doAutoImport() {
8484
importStatus.value.isWorking = true;
8585
importStatus.value.failed = [];
8686
87-
// 遍历所有需要添加的站点
87+
// 遍历所有需要添加的站点,在遍历过程中我们不更新 siteHostMap 和 siteNameMap
8888
for (const site of importStatus.value.toWork) {
8989
if (importStatus.value.success.includes(site)) {
9090
continue; // 如果已经添加成功,则跳过
@@ -101,13 +101,15 @@ async function doAutoImport() {
101101
102102
// 对于 public 站点,不需要额外测试是否能够搜索
103103
if (siteMetadata.type === "public") {
104-
await metadataStore.addSite(site, siteUserConfig); // 直接将该站点设置存入 metadataStore
104+
// 直接将该站点设置存入 metadataStore
105+
await metadataStore.addSite(site, siteUserConfig, { reBuildMap: false }); // 抑制 site{Name, Host}Map 更新
105106
isThisSiteSuccess = true;
106107
} else {
107108
// 遍历所有 private site 预设的 urls ,找到用户实际使用的 url
108109
for (const siteUrl of siteMetadata.urls) {
109110
siteUserConfig.url = siteUrl;
110-
await metadataStore.addSite(site, siteUserConfig); // 临时将该设置存入 metadataStore
111+
// 临时将该设置存入 metadataStore
112+
await metadataStore.addSite(site, siteUserConfig, { reBuildMap: false });
111113
const { status: testStatus } = await sendMessage("getSiteSearchResult", { siteId: site });
112114
if (testStatus === EResultParseStatus.success) {
113115
isThisSiteSuccess = true; // 如果搜索成功,说明该站点可以自动添加
@@ -120,7 +122,8 @@ async function doAutoImport() {
120122
importStatus.value.success.push(site);
121123
} else {
122124
importStatus.value.failed.push(site);
123-
await metadataStore.removeSite(site); // 如果搜索失败,说明该站点不能自动添加,移除在 metadataStore 中临时添加的配置项
125+
// 如果搜索失败,说明该站点不能自动添加,移除在 metadataStore 中临时添加的配置项
126+
await metadataStore.removeSite(site, { reBuildMap: false });
124127
}
125128
} catch (e) {
126129
importStatus.value.failed.push(site);
@@ -131,7 +134,13 @@ async function doAutoImport() {
131134
importStatus.value.isWorking = false;
132135
importStatus.value.toWork = [];
133136
134-
runtimeStore.showSnakebar(t("SetSite.oneClickImportDialog.importComplete", { count: importStatus.value.success.length }), { color: "success" });
137+
// 所有导入完成,重构 site{Host, Name}Map
138+
await metadataStore.buildSiteMapCache(true);
139+
140+
runtimeStore.showSnakebar(
141+
t("SetSite.oneClickImportDialog.importComplete", { count: importStatus.value.success.length }),
142+
{ color: "success" },
143+
);
135144
}
136145
137146
async function dialogEnter() {

0 commit comments

Comments
 (0)