Skip to content

Commit 5d165ae

Browse files
authored
Merge pull request #34 from alfredt999/main
修復1月更新後聊天預覽無法顯示
2 parents f2dee06 + 23f1983 commit 5d165ae

22 files changed

Lines changed: 268 additions & 14112 deletions

frontend/components/SettingsDialog.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,10 @@
289289
</template>
290290

291291
<script setup>
292-
import { DESKTOP_SETTING_AUTO_REALTIME_KEY, DESKTOP_SETTING_DEFAULT_TO_CHAT_KEY, SNS_SETTING_USE_CACHE_KEY, readLocalBoolSetting, writeLocalBoolSetting } from '~/utils/desktop-settings'
293-
import { readApiBaseOverride, writeApiBaseOverride } from '~/utils/api-settings'
294-
import { reportServerErrorFromError } from '~/utils/server-error-logging'
292+
import { DESKTOP_SETTING_AUTO_REALTIME_KEY, DESKTOP_SETTING_DEFAULT_TO_CHAT_KEY, SNS_SETTING_USE_CACHE_KEY, readLocalBoolSetting, writeLocalBoolSetting } from '~/lib/desktop-settings'
293+
import { readApiBaseOverride, writeApiBaseOverride } from '~/lib/api-settings'
294+
import { invalidateApiBaseCache } from '~/composables/useApiBase'
295+
import { reportServerErrorFromError } from '~/lib/server-error-logging'
295296
296297
const props = defineProps({
297298
open: {
@@ -624,6 +625,7 @@ const applyDesktopBackendPort = async () => {
624625
const host = String(window.location?.hostname || '').trim() || '127.0.0.1'
625626
const nextOrigin = `${protocol}//${host}:${n}`
626627
writeApiBaseOverride(`${nextOrigin}/api`)
628+
invalidateApiBaseCache()
627629
628630
const waitForHealth = async (healthUrl, timeoutMs = 30_000) => {
629631
const startedAt = Date.now()

frontend/components/wrapped/cards/Card04EmojiUniverse.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
<script setup>
261261
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue'
262262
import Stack from '~/components/wrapped/shared/VueBitsStack.vue'
263-
import WechatEmojiTable, { parseTextWithEmoji } from '~/utils/wechat-emojis'
263+
import WechatEmojiTable, { parseTextWithEmoji } from '~/lib/wechat-emojis'
264264
265265
const props = defineProps({
266266
card: { type: Object, required: true },

frontend/components/wrapped/cards/Card06KeywordsWordCloud.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ import { computed, inject, onBeforeUnmount, onMounted, ref, watch } from 'vue'
9999
import { storeToRefs } from 'pinia'
100100
import { gsap } from 'gsap'
101101
import KeywordWordCloud from '~/components/wrapped/visualizations/KeywordWordCloud.vue'
102-
import { parseTextWithEmoji } from '~/utils/wechat-emojis'
102+
import { parseTextWithEmoji } from '~/lib/wechat-emojis'
103103
import { usePrivacyStore } from '~/stores/privacy'
104104
105105
const props = defineProps({

frontend/components/wrapped/visualizations/AnnualCalendarHeatmap.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
</template>
108108

109109
<script setup>
110-
import { heatColor } from '~/utils/wrapped/heatmap'
110+
import { heatColor } from '~/lib/wrapped/heatmap'
111111
112112
const props = defineProps({
113113
year: { type: Number, default: new Date().getFullYear() },

frontend/components/wrapped/visualizations/KeywordWordCloud.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<script setup>
101101
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
102102
import { storeToRefs } from 'pinia'
103-
import { parseTextWithEmoji } from '~/utils/wechat-emojis'
103+
import { parseTextWithEmoji } from '~/lib/wechat-emojis'
104104
import { usePrivacyStore } from '~/stores/privacy'
105105
106106
const props = defineProps({

frontend/components/wrapped/visualizations/WeekdayHourHeatmap.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
</template>
6060

6161
<script setup>
62-
import { heatColor, maxInMatrix, formatHourRange } from '~/utils/wrapped/heatmap'
62+
import { heatColor, maxInMatrix, formatHourRange } from '~/lib/wrapped/heatmap'
6363
6464
const props = defineProps({
6565
weekdayLabels: { type: Array, default: () => ['周一', '周二', '周三', '周四', '周五', '周六', '周日'] },

frontend/composables/useApi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { reportServerError } from '~/utils/server-error-logging'
1+
import { reportServerError } from '~/lib/server-error-logging'
22

33
// API请求组合式函数
44
export const useApi = () => {

frontend/composables/useApiBase.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1-
import { normalizeApiBase, readApiBaseOverride } from '~/utils/api-settings'
1+
import { normalizeApiBase, readApiBaseOverride } from '~/lib/api-settings'
2+
3+
// Client-side cache so that useApiBase() can be called safely outside
4+
// the Nuxt composable context (e.g. inside async callbacks / onMounted chains).
5+
let _clientCache = ''
26

37
export const useApiBase = () => {
4-
const config = useRuntimeConfig()
8+
if (process.client && _clientCache) return _clientCache
9+
10+
// useRuntimeConfig() requires the Nuxt app context, which is only
11+
// guaranteed during synchronous setup. On the client we cache the
12+
// result so later (context-less) calls still work.
13+
let config
14+
try {
15+
config = useRuntimeConfig()
16+
} catch {
17+
// Context unavailable – fall back to cached value or default.
18+
return _clientCache || '/api'
19+
}
520

621
// Default to same-origin `/api` so Nuxt devProxy / backend-mounted UI both work.
722
// Override priority:
@@ -10,5 +25,16 @@ export const useApiBase = () => {
1025
// 3) `/api`
1126
const override = process.client ? readApiBaseOverride() : ''
1227
const runtime = String(config?.public?.apiBase || '').trim()
13-
return normalizeApiBase(override || runtime || '/api')
28+
const result = normalizeApiBase(override || runtime || '/api')
29+
30+
if (process.client) _clientCache = result
31+
return result
32+
}
33+
34+
/**
35+
* Call this when the user changes the API base override in settings
36+
* so the cached value is refreshed.
37+
*/
38+
export const invalidateApiBaseCache = () => {
39+
_clientCache = ''
1440
}

0 commit comments

Comments
 (0)