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'
|
2022-08-08 15:37:06 +08:00
|
|
|
|
path && !path.startsWith('/') && !path.startsWith('http') && (path = '/'.concat(path));
|
2020-10-22 19:34:11 +08:00
|
|
|
|
const local = 'https://testforgeplus.trustie.net';
|
|
|
|
|
|
if (isDev) {
|
2022-08-08 15:37:06 +08:00
|
|
|
|
return `${local}${path}`
|
2020-10-22 18:20:42 +08:00
|
|
|
|
}
|
2021-04-19 18:19:21 +08:00
|
|
|
|
return `${path}`;
|
2020-10-22 18:20:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-17 10:46:09 +08:00
|
|
|
|
export function isPhone(){
|
2023-07-18 17:49:20 +08:00
|
|
|
|
var userAgentInfo = navigator.userAgent;
|
|
|
|
|
|
var Agents = ["Android", "iPhone",
|
|
|
|
|
|
"SymbianOS", "Windows Phone",
|
|
|
|
|
|
"iPad", "iPod"];
|
|
|
|
|
|
var flag = false;
|
|
|
|
|
|
for (var v = 0; v < Agents.length; v++) {
|
|
|
|
|
|
if (userAgentInfo.indexOf(Agents[v]) > 0) {
|
|
|
|
|
|
flag = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return flag;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-08 16:52:40 +08:00
|
|
|
|
export function getImageUrlAbsolute(path) {
|
|
|
|
|
|
// https://www.educoder.net
|
|
|
|
|
|
// https://testbdweb.trustie.net
|
|
|
|
|
|
// const local = 'http://localhost:3000'
|
|
|
|
|
|
path && !path.startsWith('/') && !path.startsWith('http') && (path = '/'.concat(path));
|
|
|
|
|
|
const local = 'https://testforgeplus.trustie.net';
|
|
|
|
|
|
const prod = window.location.origin;
|
|
|
|
|
|
if (isDev) {
|
|
|
|
|
|
return `${local}${path}`
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return `${prod}${path}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-12 11:45:56 +08:00
|
|
|
|
export function numFormat(num, digits){
|
|
|
|
|
|
let d = digits || 1;
|
|
|
|
|
|
var si = [
|
|
|
|
|
|
{ value: 1, symbol: "" },
|
|
|
|
|
|
{ value: 1E3, symbol: "k" },
|
|
|
|
|
|
{ value: 1E4, symbol: "W" }
|
|
|
|
|
|
];
|
|
|
|
|
|
var rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
|
|
|
|
|
|
var i;
|
|
|
|
|
|
for (i = si.length - 1; i > 0; i--) {
|
|
|
|
|
|
if (num >= si[i].value) {
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return (num / si[i].value).toFixed(d).replace(rx, "$1") + si[i].symbol;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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) {
|
2023-12-13 17:08:42 +08:00
|
|
|
|
// const local = 'http://172.20.32.202:8080'
|
|
|
|
|
|
// if (isDev) {
|
|
|
|
|
|
// return `${local}${path?path:''}`
|
|
|
|
|
|
// }
|
2020-03-16 14:12:11 +08:00
|
|
|
|
return `${path ? path: ''}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-15 10:28:34 +08:00
|
|
|
|
export function getZoneUrl(path) {
|
2023-06-15 10:48:00 +08:00
|
|
|
|
|
|
|
|
|
|
let settings = localStorage.chromesetting&&JSON.parse(localStorage.chromesetting);
|
|
|
|
|
|
let actionUrl = settings && settings.common.zone;
|
|
|
|
|
|
|
|
|
|
|
|
return `${actionUrl}${path?path:''}`
|
2023-06-15 10:28:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
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) {
|
2021-04-01 14:41:13 +08:00
|
|
|
|
return `${getUrl()}/api/attachments.json${isDev ?`${isDev ?`?debug=${window._debugType || 'admin'}` : ""}` : ""}`;
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-04-28 17:23:34 +08:00
|
|
|
|
export function getUploadLogoActionUrl() {
|
2021-04-01 14:41:13 +08:00
|
|
|
|
return `${getUrl()}/api/resumes/logo.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`;
|
2020-04-28 17:23:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
export function getUploadActionUrltwo(id) {
|
2021-04-01 14:41:13 +08:00
|
|
|
|
return `${getUrlmys()}/api/shixuns/${id}/upload_data_sets.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`
|
2020-03-16 14:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getUploadActionUrlthree() {
|
2021-04-01 14:41:13 +08:00
|
|
|
|
return `${getUrlmys()}/api/jupyters/import_with_tpm.json${isDev ?`?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) {
|
2021-04-01 14:41:13 +08:00
|
|
|
|
return `${getUrlmys()}/api/shixuns/${id}/upload_git_file.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`
|
2020-04-28 17:23:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-16 14:12:11 +08:00
|
|
|
|
export function getUploadActionUrlOfAuth(id) {
|
2021-04-01 14:41:13 +08:00
|
|
|
|
return `${getUrl()}/api/users/accounts/${id}/auth_attachment.json${isDev ?`?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, "<");
|
|
|
|
|
|
s = s.replace(/>/g, ">");
|
|
|
|
|
|
s = s.replace(/ /g, " ");
|
|
|
|
|
|
s = s.replace(/\'/g, "'");//IE下不支持实体名称
|
|
|
|
|
|
s = s.replace(/\"/g, """);
|
|
|
|
|
|
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>)
|
|
|
|
|
|
}
|
2021-12-22 18:29:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function turnbar(str){
|
|
|
|
|
|
let s = str;
|
|
|
|
|
|
if(s && s.length>0){
|
|
|
|
|
|
if(s.indexOf("%")>-1){
|
2021-12-23 14:07:12 +08:00
|
|
|
|
s = s.replaceAll('%','_25');
|
2021-12-22 18:29:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(s.indexOf("#")>-1){
|
|
|
|
|
|
s = s.replaceAll('#','%23');
|
|
|
|
|
|
}
|
|
|
|
|
|
if(s.indexOf("/")>-1){
|
|
|
|
|
|
s = s.replaceAll('/','%2F');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return s;
|
|
|
|
|
|
}
|
|
|
|
|
|
export function returnbar(str){
|
|
|
|
|
|
let s = str;
|
|
|
|
|
|
if(s && s.length>0){
|
2021-12-23 14:07:12 +08:00
|
|
|
|
if(str.indexOf("_25")>-1){
|
|
|
|
|
|
s = s.replaceAll('_25','%');
|
2021-12-22 18:29:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(s.indexOf("%23")>-1){
|
|
|
|
|
|
s = s.replaceAll('%23','#');
|
|
|
|
|
|
}
|
|
|
|
|
|
if(s.indexOf("%2F")>-1){
|
|
|
|
|
|
s = s.replaceAll('%2F','/');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return s;
|
2023-01-13 17:10:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 手动添加/修改mate标签
|
|
|
|
|
|
export function addMeta(name, content){
|
|
|
|
|
|
if(document.querySelector(`meta[name='${name}']`)){
|
|
|
|
|
|
document.querySelector(`meta[name='${name}']`).content=content;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
const meta = document.createElement('meta');
|
|
|
|
|
|
meta.content = content;
|
|
|
|
|
|
meta.name = name;
|
|
|
|
|
|
document.getElementsByTagName('head')[0].appendChild(meta);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置meta中的og:title,og:description,og:url,twitter:title等,优化seo
|
|
|
|
|
|
* keyWords 关键词
|
|
|
|
|
|
* title 网页标题
|
|
|
|
|
|
* description 描述
|
|
|
|
|
|
* url 网页地址
|
|
|
|
|
|
* owner 项目拥有者或者个人主页用户login
|
|
|
|
|
|
* projectId 项目唯一标识
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function setSeoMeta(keyWords, title, description, url, owner, projectId) {
|
2024-03-15 16:24:12 +08:00
|
|
|
|
// 服务端没有location
|
2024-03-18 14:07:40 +08:00
|
|
|
|
const host = window.location.host
|
|
|
|
|
|
const origin = window.location.origin
|
2024-03-15 16:24:12 +08:00
|
|
|
|
document.querySelector(`meta[property='og:title']`).content = title + ' | GitLink';
|
|
|
|
|
|
document.querySelector(`title`).textContent = title + ' | GitLink';
|
|
|
|
|
|
document.querySelector(`meta[property='og:url']`).content = origin + url;
|
|
|
|
|
|
document.querySelector(`meta[property='og:description']`).content = description + ' | GitLink';
|
|
|
|
|
|
document.querySelector(`meta[property='og:image:alt']`).content = description + ' | GitLink';
|
|
|
|
|
|
document.querySelector('meta[name="Keywords"]').content= `${ keyWords },${ keyWords ? '' : 'GitLink, git, 开源, 代码托管, 项目管理, 版本控制, 代码分享, 项目协作, 协同开发平台' }` ;
|
|
|
|
|
|
document.querySelector(`meta[name='description']`).content = description + ' | GitLink';
|
|
|
|
|
|
document.querySelector(`meta[name='go-import']`).content = host + url + ' git ' + origin + url;
|
2023-01-13 17:10:03 +08:00
|
|
|
|
document.querySelector(`meta[name='octolytics-dimension-user_login']`).content = owner;
|
|
|
|
|
|
if (projectId) {
|
|
|
|
|
|
document.querySelector(`meta[name='octolytics-dimension-repository_nwo']`).content = owner + '/' + projectId;
|
|
|
|
|
|
document.querySelector(`meta[name='octolytics-dimension-repository_network_root_nwo']`).content = owner + '/' + projectId;
|
|
|
|
|
|
}
|
2024-03-15 16:24:12 +08:00
|
|
|
|
document.querySelector(`link[rel='canonical']`).href = origin + url;
|
2021-12-22 18:29:23 +08:00
|
|
|
|
}
|