Commit 3dda1abf authored by chenshouchao's avatar chenshouchao

feat: 文件操作请求封装部分提交

parent dc91b190
...@@ -4,12 +4,14 @@ import axios from "axios"; ...@@ -4,12 +4,14 @@ import axios from "axios";
// import { Actions, Constants } from '../../../../commons/utils/constants' // import { Actions, Constants } from '../../../../commons/utils/constants'
// import MessageUtil from '../../../../commons/utils/MessageUtil' // import MessageUtil from '../../../../commons/utils/MessageUtil'
// import ApiUtils from '../../../../commons/utils/ApiUtils' // import ApiUtils from '../../../../commons/utils/ApiUtils'
// import { APIOPTION, urlToken, ZONEID } from '../../../../commons/utils/raysyncApi' import { APIOPTION, urlToken, ZONEID } from "./raysyncApi";
// import UserStore from '../../../../console/common/stores/UserStore' // import UserStore from '../../../../console/common/stores/UserStore'
import { ApiUtils } from "./utils";
import Base64 from "crypto-js/enc-base64"; import Base64 from "crypto-js/enc-base64";
import Utf8 from "crypto-js/enc-utf8"; import Utf8 from "crypto-js/enc-utf8";
import { getLoaclStorageOfKey } from "./utils";
let headers = { let headers: any = {
"Content-Type": "application/json", "Content-Type": "application/json",
}; };
...@@ -51,6 +53,43 @@ class CloudEController { ...@@ -51,6 +53,43 @@ class CloudEController {
// }); // });
// } // }
// } // }
// 文件列表
static JobOutFileList(
url: any,
showHide = false,
filetoken: string,
items?: any
) {
if (ApiUtils.getAuthorizationHeaders(headers)) {
headers["Cache-Control"] = "no-cache";
// headers['parentName'] = ''
if (getLoaclStorageOfKey("userinfo")) {
url += urlToken(filetoken);
}
axios
//修改 查看文件的接口为list(可查看隐藏文件)
.get(APIOPTION() + "/list" + url + "&showhidden=" + showHide, {
headers: headers,
})
.then(function (response) {
console.log(response);
// Array.isArray(response.data)
// ? CloudEStore.setjobOutFileList(response.data)
// : CloudEStore.setjobOutFileList([]);
// CloudEStore.emitChange(
// Actions.JobOutFileList,
// true,
// Actions.JobOutFileList,
// items
// );
})
.catch(function (error) {
console.log(error);
// MessageUtil.handleError(CloudEStore, error);
// CloudEStore.emitChange(Actions.JobOutFileList, false);
});
}
}
// // 文件列表 // // 文件列表
// static JobOutFileList(url, showHide = false, items) { // static JobOutFileList(url, showHide = false, items) {
// if ( // if (
......
// const API = "https://fileserver.cloudam.cn:8091" // const API = "https://fileserver.cloudam.cn:8091"
// const APIOPTION = "https://fileserver.cloudam.cn" // const APIOPTION = "https://fileserver.cloudam.cn"
// const APIPORT = "39.105.230.38" // const APIPORT = "39.105.230.38"
import { getLoaclStorageOfKey } from "./utils";
// const raysyncAddr = { // const raysyncAddr = {
// bandwidth: null // bandwidth: null
// capacity: 10485760 // capacity: 10485760
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
// zoneId: "cn-beijing-h" // zoneId: "cn-beijing-h"
// } // }
const getLoaclStorageOfKey = (key: string) => {
return JSON.parse(localStorage.getItem(key) || "");
};
const API = function () { const API = function () {
const raysyncAddr = getLoaclStorageOfKey("raysyncAddr"); const raysyncAddr = getLoaclStorageOfKey("raysyncAddr");
return raysyncAddr.srcAddr ? `https://${raysyncAddr.srcAddr}:8091` : ""; return raysyncAddr.srcAddr ? `https://${raysyncAddr.srcAddr}:8091` : "";
...@@ -107,23 +103,19 @@ const ZONEID = (params: string) => { ...@@ -107,23 +103,19 @@ const ZONEID = (params: string) => {
return currentRegion[params || "id"] || ""; return currentRegion[params || "id"] || "";
}; };
const urlToken = (root: string) => { const urlToken = (filetoken: string, root?: string) => {
let token = getLoaclStorageOfKey("token").access_token; let token = getLoaclStorageOfKey("token").access_token;
let json = getLoaclStorageOfKey("current-region"); let json = getLoaclStorageOfKey("current-region");
const userInfo = getLoaclStorageOfKey("userinfo"); const userInfo = getLoaclStorageOfKey("userinfo");
if (json["location"] && json["location"] === "ON_PREMISE") { if (json["location"] && json["location"] === "ON_PREMISE") {
return `?username=${ return `?username=${
userInfo["name"] userInfo["name"]
}&token=${token}&filetoken=${encodeURIComponent( }&token=${token}&filetoken=${encodeURIComponent(filetoken)}&share=false`; // 之前的filetoken是: userInfo["shareFileAccessToken"]
userInfo["onpremFileAccessToken"]
)}&share=false`;
} }
if (root && root === "home") { if (root && root === "home") {
return `?username=${ return `?username=${
userInfo["homeDirectoryMountPoint"] userInfo["homeDirectoryMountPoint"]
}&token=${token}&filetoken=${encodeURIComponent( }&token=${token}&filetoken=${encodeURIComponent(filetoken)}&share=false`;
userInfo["fileAccessToken"]
)}&share=false`;
} }
// 是否共有文件系统 // 是否共有文件系统
if ( if (
...@@ -132,15 +124,11 @@ const urlToken = (root: string) => { ...@@ -132,15 +124,11 @@ const urlToken = (root: string) => {
) { ) {
return `?username=${ return `?username=${
userInfo["shareDirectoryMountPoint"] userInfo["shareDirectoryMountPoint"]
}&token=${token}&filetoken=${encodeURIComponent( }&token=${token}&filetoken=${encodeURIComponent(filetoken)}&share=true`;
userInfo["shareFileAccessToken"]
)}&share=true`;
} else { } else {
return `?username=${ return `?username=${
userInfo["homeDirectoryMountPoint"] userInfo["homeDirectoryMountPoint"]
}&token=${token}&filetoken=${encodeURIComponent( }&token=${token}&filetoken=${encodeURIComponent(filetoken)}&share=false`;
userInfo["fileAccessToken"]
)}&share=false`;
} }
}; };
......
export const ApiUtils = {}; // import { Constants, MESSAGETIP } from "./constants";
export const getLoaclStorageOfKey = (key: string) => {
return JSON.parse(localStorage.getItem(key) || "{}");
};
export const isEn = () => {
return (
(localStorage.getItem("language") &&
localStorage.getItem("language") === "en") ||
[
"www.cloudam.se",
"47.75.109.159",
"47.57.235.86",
"www.cloudam.io",
].includes(window.location.host)
);
};
export class ApiUtils {
static getAuthorizationHeaders(headers: any) {
let token_key = getLoaclStorageOfKey("token_key");
if (!token_key) {
if (
window.location.pathname.indexOf("/login-page") > -1 ||
window.location.pathname.indexOf("/pages/Internlogin-page") > -1
) {
return false;
} else {
setTimeout(() => {
// localStorage.removeItem("temporary_token_key");
// localStorage.removeItem("token_key");
if (
window.location.href &&
!window.location.href.includes("/login-page") &&
!window.location.href.includes("/pages/Internlogin-page")
)
isEn()
? (window.location.href = "/v2/pages/Internlogin-page")
: (window.location.href = "/v2/pages/login-page");
}, 4000);
}
return false;
}
let token = token_key.access_token;
headers["Authorization"] = "Bearer " + token;
headers["Accept-Language"] =
localStorage.getItem("language") === "en"
? "en-US,en;q=0.5"
: "zh-CN,zh,q=0.5";
return true;
}
// 临时token
static getTemporaryAuthorizationHeaders(obj: any, headers: any, action: any) {
if (!localStorage.getItem("temporary_token_key")) {
obj.setError({
errorCode: "x0001",
message: "临时登陆凭证过期或失效,请重新连接云账号",
});
obj.emitChange(action, false);
return false;
}
headers["Authorization"] =
"Bearer " + getLoaclStorageOfKey("temporary_token_key").access_token;
headers["Accept-Language"] =
localStorage.getItem("language") === "en"
? "en-US,en;q=0.5"
: "zh-CN,zh,q=0.5";
return true;
}
static poll(fn: any, timeout: number, interval: number) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
let hasCanceled = false;
var checkCondition = function (resolve: any, reject: any) {
if (hasCanceled) {
reject({ isCanceled: true, type: "1" }); //type ===1 用户手动取消
return;
}
// If the condition is met, we're done!
var result = fn();
if (result) {
resolve(result);
}
// If the condition isn't met but the timeout hasn't elapsed, go again
else if (Number(new Date()) < endTime) {
setTimeout(checkCondition, interval, resolve, reject);
}
// Didn't match and too much time, reject!
else {
reject({ isCanceled: true, type: "2" });
}
};
const wrappedPromise = new Promise(checkCondition);
return {
promise: wrappedPromise,
cancel() {
hasCanceled = true;
},
};
}
}
...@@ -20,6 +20,7 @@ import UpLoaderFile from "./UpLoaderFile"; ...@@ -20,6 +20,7 @@ import UpLoaderFile from "./UpLoaderFile";
import useMyRequest from "@/hooks/useMyRequest"; import useMyRequest from "@/hooks/useMyRequest";
import { observer } from "mobx-react-lite"; import { observer } from "mobx-react-lite";
import { useStores } from "@/store"; import { useStores } from "@/store";
import CloudEController from "@/api/fileserver/CloudEController";
const theme = createTheme({ const theme = createTheme({
palette: { palette: {
...@@ -49,7 +50,8 @@ declare module "@mui/material/Button" { ...@@ -49,7 +50,8 @@ declare module "@mui/material/Button" {
const ProjectData = observer(() => { const ProjectData = observer(() => {
const { currentProjectStore } = useStores(); const { currentProjectStore } = useStores();
const [path, setPath] = useState("ProjectData"); // const [path, setPath] = useState("/ProjectData");
const [path, setPath] = useState("/");
const [activeTab, setActiveTab] = useState(1); const [activeTab, setActiveTab] = useState(1);
const [keyWord, setKeyWord] = useState(""); const [keyWord, setKeyWord] = useState("");
const [fileToken, setFileToken] = useState(""); const [fileToken, setFileToken] = useState("");
...@@ -61,6 +63,18 @@ const ProjectData = observer(() => { ...@@ -61,6 +63,18 @@ const ProjectData = observer(() => {
}, },
}); });
useEffect(() => {
if (fileToken) {
CloudEController.JobOutFileList(path, false, fileToken);
// 老项目测试环境
// https://fileserver.cloudam.cn/list/?username=6c8928fa719940dc964cf17a029b36c5&token=d1b07aa2-0b29-48ca-ad28-bb41af3bcbb1&filetoken=%2FMm%2BLhFrOpEDp0neVeESSD%2F45aY%3D&share=false&showhidden=false
// 新项目本地
// https://fileserver.cloudam.cn/list/?username=8e12a4fdde5549b0aa8b3051ff8c8f04&token=751cd163-fe95-45d0-8f7a-3d0d8b8bb442&filetoken=isZw%2B%2BzeJO3R34BEXTjmmovFOmA%3D&share=false&showhidden=false
// 老项目本地
// https://fileserver.cloudam.cn/list/?username=6c8928fa719940dc964cf17a029b36c5&token=d1b07aa2-0b29-48ca-ad28-bb41af3bcbb1&filetoken=bUt%2Bn0YacgepFClLR4LNR0MxW0w%3D&share=false&showhidden=false
}
}, [fileToken, path]);
useEffect(() => { useEffect(() => {
getDataFileTokenRun({ getDataFileTokenRun({
id: currentProjectStore.currentProjectInfo.id as string, id: currentProjectStore.currentProjectInfo.id as string,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment