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 = {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
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}`
|
|
|
|
}
|