2021-04-24 05:56:56 -04:00
|
|
|
import logger from '@core/picgo/logger'
|
|
|
|
|
2019-12-31 10:50:19 -05:00
|
|
|
export const handleResponse = ({
|
|
|
|
response,
|
|
|
|
statusCode = 200,
|
|
|
|
header = {
|
2022-07-15 22:36:00 -04:00
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'access-control-allow-headers': '*',
|
|
|
|
'access-control-allow-methods': 'POST, GET, OPTIONS',
|
|
|
|
'access-control-allow-origin': '*'
|
2019-12-31 10:50:19 -05:00
|
|
|
},
|
|
|
|
body = {
|
|
|
|
success: false
|
|
|
|
}
|
|
|
|
} : {
|
|
|
|
response: IHttpResponse,
|
|
|
|
statusCode?: number,
|
|
|
|
header?: IObj,
|
|
|
|
body?: any
|
|
|
|
}) => {
|
2021-04-24 05:56:56 -04:00
|
|
|
if (body?.success === false) {
|
|
|
|
logger.warn('[PicGo Server] upload failed, see picgo.log for more detail ↑')
|
|
|
|
}
|
2019-12-31 10:50:19 -05:00
|
|
|
response.writeHead(statusCode, header)
|
|
|
|
response.write(JSON.stringify(body))
|
|
|
|
response.end()
|
|
|
|
}
|
2020-03-19 07:25:05 -04:00
|
|
|
|
|
|
|
export const ensureHTTPLink = (url: string): string => {
|
|
|
|
return url.startsWith('http')
|
|
|
|
? url
|
|
|
|
: `http://${url}`
|
|
|
|
}
|