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.
56 lines
1.6 KiB
56 lines
1.6 KiB
"use strict";
|
|
const fs = require("fs")
|
|
const path = require("path")
|
|
const _ = require("lodash");
|
|
const { Controller } = require("egg");
|
|
const { promisify } = require("util");
|
|
class setgetdataController extends Controller {
|
|
//设置收藏数据
|
|
async setRouterFav() {
|
|
let { ctx, service } = this;
|
|
let params = ctx.request.body
|
|
let res = await service.home.setRouterFav(params);
|
|
ctx.body = res;
|
|
}
|
|
//获取收藏数据
|
|
async getRouterFav() {
|
|
let { ctx, service } = this;
|
|
let params = ctx.request.body
|
|
let res = await service.home.getRouterFav(params);
|
|
ctx.body = res;
|
|
}
|
|
//获取文件
|
|
async getFile() {
|
|
let { ctx } = this;
|
|
let url = ctx.request.url
|
|
let fileNameArr = _.split(url, "=")
|
|
let filePath = `${ctx.app.baseDir}/app/public/file/${_.get(fileNameArr, [1])}`
|
|
// let fileSize = (await promisify(fs.stat)(filePath)).size.toString()
|
|
// ctx.attachment(filePath);
|
|
// ctx.set('Content-Length', fileSize);
|
|
// ctx.set('content-Type', 'application/octet-stream');
|
|
// ctx.set('Content-Disposition', `attachment; filename=${_.get(fileNameArr, [1])}`)
|
|
console.log(9744, await ctx.downloader(filePath))
|
|
ctx.boby = await ctx.downloader(filePath);
|
|
}
|
|
//获取瓦片地图
|
|
async getMapPng() {
|
|
let { ctx, service } = this;
|
|
let params = {
|
|
url: ctx.request.url
|
|
}
|
|
console.log(7878774,params)
|
|
let pathRes = await service.home.getMapPng(params);
|
|
ctx.set('content-type', 'image/jpeg')
|
|
if (pathRes) {
|
|
try {
|
|
ctx.body = fs.createReadStream(pathRes);
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = setgetdataController;
|
|
|