|
@@ -102,9 +102,6 @@ router.get("/:record_id", async function (req, res) {
|
|
|
const record_id = req.params.record_id; // 获取 fileId 参数
|
|
|
const recordInfo = await getRecordInfoById(record_id);
|
|
|
const files = await getFileByRecordId(record_id);
|
|
|
- // 获取请求的来源域名
|
|
|
- // const host = req.headers['host']; // 主机名 + 端口
|
|
|
- const origin = req.headers["host"]; // 请求的来源域(适用于跨域)
|
|
|
|
|
|
const typesRes = await getTypesById({
|
|
|
typeId: recordInfo.type_id,
|
|
@@ -116,20 +113,30 @@ router.get("/:record_id", async function (req, res) {
|
|
|
} else {
|
|
|
recordInfo.type = "";
|
|
|
}
|
|
|
-
|
|
|
+ // http://127.0.0.1:20040/?zs_interval=1732419124661/api/v1/files/6a3beffd24ee92a0b0846afaf2196b14
|
|
|
+
|
|
|
+ // http://localhost:3000/?zs_interval=1732420198559/api/v1/files/aace8ebb259f6e70ef5b0c1f8efde3ae
|
|
|
+ function getFileUrl(elm) {
|
|
|
+ // 获取请求的来源域名
|
|
|
+ const host = req.headers['host']; // 主机名 + 端口
|
|
|
+ const origin = req.headers["referer"]; // 请求的来源域(适用于跨域)
|
|
|
+ if (`${origin}`.indexOf("3032") > -1 || `${host}`.indexOf('3000') > -1) {
|
|
|
+ return "http://localhost:3000" + `/api/v1/files/${elm.file_id}`;
|
|
|
+ }
|
|
|
+ if (`${origin}`.indexOf("zs_interval") > -1) {
|
|
|
+ return `http://${origin.replace('/static/', '')}/api/v1/files/${elm.file_id}`;
|
|
|
+ }
|
|
|
+ return `${origin}api/v1/files/${elm.file_id}`;
|
|
|
+ }
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
data: {
|
|
|
+ headers: req.headers,
|
|
|
...recordInfo,
|
|
|
time: shanghaiTimeFormat(recordInfo.time, "YYYY-MM-DD"),
|
|
|
create_time: shanghaiTimeFormat(recordInfo.create_time),
|
|
|
update_time: shanghaiTimeFormat(recordInfo.update_time),
|
|
|
- files: files.map(
|
|
|
- (elm) =>
|
|
|
- `${
|
|
|
- `${origin}`.indexOf("3032") > -1 ? "http://localhost:3000" : origin
|
|
|
- }/api/v1/files/${elm.file_id}`
|
|
|
- ),
|
|
|
+ files: files.map((elm) => getFileUrl(elm)),
|
|
|
},
|
|
|
});
|
|
|
});
|
|
@@ -149,6 +156,7 @@ router.put("/:record_id", async function (req, res) {
|
|
|
|
|
|
const getAllfiles = await getFileByRecordId(record_id);
|
|
|
const getAllfilesIds = getAllfiles.map((elm) => elm.file_id);
|
|
|
+ console.log(159, getAllfiles);
|
|
|
|
|
|
const dellFilesInRecordFiles = getAllfiles.filter(
|
|
|
(elm) => files.indexOf(elm.file_id) < 0
|
|
@@ -159,7 +167,9 @@ router.put("/:record_id", async function (req, res) {
|
|
|
|
|
|
if (dellFilesInRecordFiles.length) {
|
|
|
await Promise.all(
|
|
|
- dellFilesInRecordFiles.map((elm) => delFileByRecordId(record_id, file_id))
|
|
|
+ dellFilesInRecordFiles.map((elm) =>
|
|
|
+ delFileByRecordId(record_id, elm.file_id)
|
|
|
+ )
|
|
|
);
|
|
|
}
|
|
|
if (needAddFiles.length) {
|