fix: 解决部分图片请求路径硬编码带有 /src/public 导致未匹配物理文件而落入 endIndex 返回 text/html 的问题

This commit is contained in:
tangxinyue 2026-07-24 15:16:55 +08:00
parent aafa8e2509
commit 85d60d9c9a
4 changed files with 21 additions and 14 deletions

View File

@ -86,14 +86,21 @@ function getMimeType(filePath) {
const matchFile = async (request, response) => { const matchFile = async (request, response) => {
return new Promise((resolve) => { return new Promise((resolve) => {
const cleanPath = decodeURIComponent(request.url.split('?')[0]) const cleanPath = decodeURIComponent(request.url.split('?')[0])
fs.readFile(dist + cleanPath, (err, file) => { let targetPath = dist + cleanPath
if (!fs.existsSync(targetPath)) {
const mappedPath = dist + cleanPath.replace(/^\/(src\/public|public|src)/, '')
if (fs.existsSync(mappedPath)) {
targetPath = mappedPath
}
}
fs.readFile(targetPath, (err, file) => {
if (!err) { if (!err) {
const mimetype = getMimeType(cleanPath) const mimetype = getMimeType(cleanPath)
const responseHdeaders = { 'Content-Type': mimetype } const responseHeaders = { 'Content-Type': mimetype }
if (cleanPath.endsWith("-sw.js")) { if (cleanPath.endsWith("-sw.js")) {
responseHdeaders["Service-Worker-Allowed"] = '/' responseHeaders["Service-Worker-Allowed"] = '/'
} }
response.writeHead(httpOk, responseHdeaders) response.writeHead(httpOk, responseHeaders)
response.end(file) response.end(file)
// logger.info(`${request.method} ${httpOk} ${request.url}`) // logger.info(`${request.method} ${httpOk} ${request.url}`)
resolve(true) resolve(true)

View File

@ -2,9 +2,9 @@
<div class="status-bar" :class="{ 'dark-mode': theme === 'dark' }" :style="{ 'background-color': bgColor }"> <div class="status-bar" :class="{ 'dark-mode': theme === 'dark' }" :style="{ 'background-color': bgColor }">
<span class="time">{{ time }}</span> <span class="time">{{ time }}</span>
<span class="status-icons"> <span class="status-icons">
<img class="signal" :src="`/src/public/status/signal-${theme === 'dark' ? 'dark-' + signal : signal}.png`" <img class="signal" :src="`/status/signal-${theme === 'dark' ? 'dark-' + signal : signal}.png`"
alt="" /> alt="" />
<img class="wifi" :src="`/src/public/status/wifi-${theme === 'dark' ? 'dark-' + wifi : wifi}.png`" alt="" /> <img class="wifi" :src="`/status/wifi-${theme === 'dark' ? 'dark-' + wifi : wifi}.png`" alt="" />
<div class="battery"> <div class="battery">
<div class="power" :class="{ 'full-power': battery >= 100 }" <div class="power" :class="{ 'full-power': battery >= 100 }"
:style="{ 'background-color': isCharging ? '#2DC752' : 'var(--battery-bg)', width: battery + '%' }"> :style="{ 'background-color': isCharging ? '#2DC752' : 'var(--battery-bg)', width: battery + '%' }">
@ -12,10 +12,10 @@
<div class="percent"> <div class="percent">
<span class="battery-text" :style="{ 'color': isCharging ? '#ffffff' : 'var(--battery-color)' }"> <span class="battery-text" :style="{ 'color': isCharging ? '#ffffff' : 'var(--battery-color)' }">
{{ battery }}</span> {{ battery }}</span>
<img v-if="isCharging" class="charging" src="/src/public/status/charging.png" alt="" /> <img v-if="isCharging" class="charging" src="/status/charging.png" alt="" />
</div> </div>
</div> </div>
<img style="width: 1px;height: 4px;margin-left: 1px;" src="/src/public/status/battery.png" alt="" /> <img style="width: 1px;height: 4px;margin-left: 1px;" src="/status/battery.png" alt="" />
</span> </span>
</div> </div>
</template> </template>

View File

@ -25,8 +25,8 @@
</div> </div>
</div> </div>
<div class="right-works" @click="$router.push('/works')"> <div class="right-works" @click="$router.push('/works')">
<img v-if="worksCount > 0" src="/src/public/profile/hasWorks.png" class="folder-icon" /> <img v-if="worksCount > 0" src="/profile/hasWorks.png" class="folder-icon" />
<img v-else src="/src/public/profile/folder.png" class="folder-icon" /> <img v-else src="/profile/folder.png" class="folder-icon" />
<span>我的作品</span> <span>我的作品</span>
</div> </div>
</div> </div>
@ -67,7 +67,7 @@
</div> </div>
</div> </div>
<div v-else class="empty-state"> <div v-else class="empty-state">
<img src="/src/public/profile/empty.png" class="empty-img" /> <img src="/profile/empty.png" class="empty-img" />
</div> </div>
</div> </div>
</div> </div>

View File

@ -468,7 +468,7 @@ const systemMsgTemplates = ref([
{ label: '+ 添加成功提示', command: '以上是打招呼的消息' }, { label: '+ 添加成功提示', command: '以上是打招呼的消息' },
{ label: '+ 账号安全', command: '对方账号不在常用环境使用,请仔细核实真实身份,涉及汇款、转账等务必电话确认,请保护自身财产和隐私安全。' }, { label: '+ 账号安全', command: '对方账号不在常用环境使用,请仔细核实真实身份,涉及汇款、转账等务必电话确认,请保护自身财产和隐私安全。' },
{ label: '+ 我要投诉', command: "对方账号安全性未知,如涉及金钱交易务必电话确认,保护个人财产和隐私安全。<span style='color: #576B95;'>我要投诉</span>" }, { label: '+ 我要投诉', command: "对方账号安全性未知,如涉及金钱交易务必电话确认,保护个人财产和隐私安全。<span style='color: #576B95;'>我要投诉</span>" },
{ label: '+ 红包领取', command: "<img style='width: 16px;height: 16px;vertical-align: middle;margin-right:7px' src='/src/public/wx-chat/receive-tip.png'></img>xxx领取了xxx的<span style='color: #F49738;'>红包</span>" } { label: '+ 红包领取', command: "<img style='width: 16px;height: 16px;vertical-align: middle;margin-right:7px' src='/wx-chat/receive-tip.png'></img>xxx领取了xxx的<span style='color: #F49738;'>红包</span>" }
]) ])
let msgIdCounter = 1 let msgIdCounter = 1
@ -630,9 +630,9 @@ function onRedpacketStatusChange(status) {
let content = "" let content = ""
const theirName = settings.theirName || '对方' const theirName = settings.theirName || '对方'
if (selectedMsg.value.sender === 'me') { if (selectedMsg.value.sender === 'me') {
content = `<img style='width: 16px;height: 16px;vertical-align: middle;margin-right:7px' src='/src/public/wx-chat/receive-tip.png'></img>${theirName}领取了你的<span style='color: #F49738;'>红包</span>` content = `<img style='width: 16px;height: 16px;vertical-align: middle;margin-right:7px' src='/wx-chat/receive-tip.png'></img>${theirName}领取了你的<span style='color: #F49738;'>红包</span>`
} else { } else {
content = `<img style='width: 16px;height: 16px;vertical-align: middle;margin-right:7px' src='/src/public/wx-chat/receive-tip.png'></img>你领取了${theirName}的<span style='color: #F49738;'>红包</span>` content = `<img style='width: 16px;height: 16px;vertical-align: middle;margin-right:7px' src='/wx-chat/receive-tip.png'></img>你领取了${theirName}的<span style='color: #F49738;'>红包</span>`
} }
messages.value.push({ messages.value.push({