forgeplus-react/src/common/UrlTool.js

236 lines
5.7 KiB
JavaScript
Raw Normal View History

2020-03-16 14:12:11 +08:00
import React from "react";
import md5 from 'md5';
import {Input} from "antd";
const { Search } = Input;
const $ = window.$;
const isDev = window.location.port == 3007;
2020-04-28 17:23:34 +08:00
const isdev2= window.location.hostname ==='www.educoder.net'
export const TEST_HOST = "https://testforgeplus.trustie.net/"
2020-03-16 14:12:11 +08:00
export function getImageUrl(path) {
// https://www.educoder.net
// https://testbdweb.trustie.net
// const local = 'http://localhost:3000'
2020-10-22 19:34:11 +08:00
const local = 'https://testforgeplus.trustie.net';
if (isDev) {
return `${local}/${path}`
2020-10-22 18:20:42 +08:00
}
2020-10-22 19:34:11 +08:00
return `/${path}`;
2020-10-22 18:20:42 +08:00
}
export function getImage(path) {
// https://www.educoder.net
// https://testbdweb.trustie.net
// const local = 'http://localhost:3000'
const local = 'https://testforgeplus.trustie.net/';
if(path.indexOf("http://")===-1){
if (isDev) {
return `${local}/images/${path}`
}
return `/${path}`;
}else{
return path;
2020-03-16 14:12:11 +08:00
}
}
2020-04-28 17:23:34 +08:00
export function getcdnImageUrl(path) {
// https://www.educoder.net
// https://testbdweb.trustie.net
// const local = 'http://localhost:3000'
const testlocal = 'https://testali-cdn.educoder.net'
const local='https://ali-cdn.educoder.net'
let firstStr=path.substr(0,1);
if (isdev2) {
return `${local}/${path}`;
}else{
if(firstStr=="/"){
return `${path}`
}else{
return `/${path}`
}
}
// return `${local}/${path}`;
}
export function setcndImagesUrl(path){
const testlocal = 'https://testali-cdn.educoder.net'
const local='https://ali-cdn.educoder.net'
let firstStr=path.substr(0,1);
if(firstStr=="/"){
if (!isdev2) {
return `${path}`
}
return `${local}${path}`;
//return isDev?`${testlocal}${path}`:`${local}${path}`;
}else{
if (!isdev2) {
return `/${path}`
}
return `${local}/${path}`;
// return isDev?`${testlocal}/${path}`:`${local}/${path}`;
}
}
2020-03-16 14:12:11 +08:00
export function setImagesUrl(path){
2020-04-28 17:23:34 +08:00
const testlocal = 'https://testali-cdn.educoder.net'
const local='https://ali-cdn.educoder.net'
2020-03-16 14:12:11 +08:00
let firstStr=path.substr(0,1);
if(firstStr=="/"){
2020-04-28 17:23:34 +08:00
if (!isdev2) {
return `${path}`
}
return `${local}${path}`;
// return isDev?`${testlocal}${path}`:`${path}`;
2020-03-16 14:12:11 +08:00
}else{
2020-04-28 17:23:34 +08:00
if (!isdev2) {
return `/${path}`
}
return `${local}/${path}`;
//return isDev?`${testlocal}/${path}`:`/${path}`;
2020-03-16 14:12:11 +08:00
}
}
export function getUrl(path, goTest) {
2020-04-29 10:42:53 +08:00
const local = 'https://testforgeplus.trustie.net'
2020-03-16 14:12:11 +08:00
if (isDev) {
return `${local}${path?path:''}`
}
return `${path ? path: ''}`;
}
export function getUrlmys(path, goTest) {
// https://www.educoder.net
// https://testbdweb.trustie.net
// 如果想所有url定位到测试版可以反注释掉下面这行
//goTest = true
// testbdweb.educoder.net testbdweb.trustie.net
// const local = goTest ? 'https://testeduplus2.educoder.net' : 'http://localhost:3000'
// const local = 'https://testeduplus2.educoder.net'
const local = 'https://test-jupyterweb.educoder.net'
if (isDev) {
return `${local}${path?path:''}`
}
return `${path ? path: ''}`;
}
export function getStaticUrl() {
const local = TEST_HOST;
if (isDev) {
return local
}
// todo cdn
return ''
}
export function getUrl2(path, goTest) {
const local = 'http://localhost:3000'
if (isDev) {
return `${local}${path?path:''}`
}
return `${path ? path: ''}`;
}
const newopens ="79e33abd4b6588941ab7622aed1e67e8";
let newtimestamp;
let checkSubmitFlgs = false;
function railsgettimess(proxy) {
if(checkSubmitFlgs===false){
$.ajax({url:proxy,
async:false,success:function(data){
if(data.status===0){
newtimestamp=data.message;
checkSubmitFlgs = true;
}
}})
window.setTimeout(function () {
checkSubmitFlgs=false;
}, 2500);
}
}
export function Railsgettimes() {
2020-04-28 17:23:34 +08:00
// railsgettimess(`${getUrl()}/api/main/first_stamp.json`);
2020-03-16 14:12:11 +08:00
// railsgettimess(`https://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp`);
}
export function getmyUrl(geturl) {
return `${getUrl()}${geturl}`;
}
export function getUploadActionUrl(path, goTest) {
2020-04-29 10:42:53 +08:00
return `${getUrl()}/api/attachments.json?debug=${window._debugType || 'admin'}`;
2020-03-16 14:12:11 +08:00
}
2020-04-28 17:23:34 +08:00
export function getUploadLogoActionUrl() {
2020-04-29 10:42:53 +08:00
return `${getUrl()}/api/resumes/logo.json?debug=${window._debugType || 'admin'}`;
2020-04-28 17:23:34 +08:00
}
2020-03-16 14:12:11 +08:00
export function getUploadActionUrltwo(id) {
2020-04-29 10:42:53 +08:00
return `${getUrlmys()}/api/shixuns/${id}/upload_data_sets.json?debug=${window._debugType || 'admin'}`
2020-03-16 14:12:11 +08:00
}
export function getUploadActionUrlthree() {
2020-04-29 10:42:53 +08:00
return `${getUrlmys()}/api/jupyters/import_with_tpm.json?debug=${window._debugType || 'admin'}`
2020-03-16 14:12:11 +08:00
}
2020-04-28 17:23:34 +08:00
export function getupload_git_file(id) {
2020-04-29 10:42:53 +08:00
return `${getUrlmys()}/api/shixuns/${id}/upload_git_file.json?debug=${window._debugType || 'admin'}`
2020-04-28 17:23:34 +08:00
}
2020-03-16 14:12:11 +08:00
export function getUploadActionUrlOfAuth(id) {
2020-04-29 10:42:53 +08:00
return `${getUrl()}/api/users/accounts/${id}/auth_attachment.json?debug=${window._debugType || 'admin'}`
2020-03-16 14:12:11 +08:00
}
export function getRandomNumber(type) {
let anewopens=md5(newopens+newtimestamp);
return type===true?`randomcode=${newtimestamp}&client_key=${anewopens}`:`?randomcode=${newtimestamp}&client_key=${anewopens}`
}
export function test(path) {
return `${path}`;
}
export function toPath(path) {
window.open(path, '_blank');
}
export function getTaskUrlById(id) {
return `/tasks/${id}`
}
export function getRandomcode(url) {
2020-04-29 10:42:53 +08:00
return url;
2020-03-16 14:12:11 +08:00
}
export function htmlEncode(str) {
var s = "";
if (str.length === 0) {
return "";
}
s = str.replace(/&/g, "&");
s = s.replace(/</g, "&lt;");
s = s.replace(/>/g, "&gt;");
s = s.replace(/ /g, "&nbsp;");
s = s.replace(/\'/g, "&#39;");//IE下不支持实体名称
s = s.replace(/\"/g, "&quot;");
return s;
}
export function publicSearchs(Placeholder,onSearch,onInputs,onChanges,loadings) {
return(<Search
placeholder= { Placeholder || "请输入内容进行搜索" }
onSearch={onSearch}
// value={searchValue}
onInput={onInputs}
onChange={onChanges}
loading={loadings||false}
allowClear={true}
></Search>)
}