Skip to content

Commit

Permalink
🐛 Fix(custom): fix compatiblity with typora
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Apr 5, 2024
1 parent e6e9472 commit 762913c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/main/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ class Server {
}
})
} else {
const remoteAddress = request.socket.remoteAddress || 'unknown'
logger.info('[PicList Server] get a POST request from IP:', remoteAddress)
let urlSP = query ? new URLSearchParams(query) : undefined
if (remoteAddress === '::1' || remoteAddress === '127.0.0.1') {
const serverKey = picgo.getConfig<string>('settings.serverKey') || ''
if (urlSP) {
urlSP.set('key', serverKey)
} else {
urlSP = new URLSearchParams('key=' + serverKey)
}
}
if (request.headers['content-type'] && request.headers['content-type'].startsWith('multipart/form-data')) {
// @ts-ignore
uploadMulter.any()(request, response, (err: any) => {
Expand All @@ -113,7 +124,7 @@ class Server {
handler({
list,
response,
urlparams: query ? new URLSearchParams(query) : undefined
urlparams: urlSP
})
}
})
Expand Down Expand Up @@ -141,7 +152,7 @@ class Server {
handler!({
...postObj,
response,
urlparams: query ? new URLSearchParams(query) : undefined
urlparams: urlSP
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/server/routerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ router.post('/upload', async ({
}): Promise<void> => {
try {
const passedKey = urlparams?.get('key')
const serverKey = picgo.getConfig('settings.serverKey') || ''
const serverKey = picgo.getConfig<string>('settings.serverKey') || ''
if (serverKey && passedKey !== serverKey) {
handleResponse({
response,
Expand Down

0 comments on commit 762913c

Please sign in to comment.