You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
787 B
30 lines
787 B
1 year ago
|
'use strict';
|
||
|
|
||
|
function realtime (opts) {
|
||
|
return async (ctx, next) => {
|
||
|
try {
|
||
|
const { models } = ctx.fs.dc;
|
||
|
const { location } = ctx.query
|
||
|
let location_ = location || '114.298156,27.717683';//经纬度字符串
|
||
|
|
||
|
const weatherRes = await ctx.app.fs.caiyunRequest.get(`${opts.caiyun.key}/${location_}/realtime`)
|
||
|
let rslt = {}
|
||
|
if (weatherRes.status == 'ok') {
|
||
|
rslt = weatherRes.result
|
||
|
}
|
||
|
|
||
|
ctx.status = 200;
|
||
|
ctx.body = rslt
|
||
|
} catch (error) {
|
||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
||
|
ctx.status = 400;
|
||
|
ctx.body = {
|
||
|
message: typeof error == 'string' ? error : undefined
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
realtime
|
||
|
}
|