391 lines
12 KiB
JavaScript
391 lines
12 KiB
JavaScript
import React from "react";
|
||
import md5 from 'md5';
|
||
import {Input} from "antd";
|
||
const { Search } = Input;
|
||
import { url as ssrOrigin, host as ssrHost } from '../ssrUrl'
|
||
|
||
|
||
// const $ = window.$;
|
||
const isDev = __SERVER__ ? false : window.location.port == 3007;
|
||
const isdev2= __SERVER__ ? false : window.location.hostname ==='www.educoder.net'
|
||
export const TEST_HOST = "https://testforgeplus.trustie.net/"
|
||
export function getImageUrl(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';
|
||
if (isDev) {
|
||
return `${local}${path}`
|
||
}
|
||
return `${path}`;
|
||
}
|
||
|
||
export function IsPC(){
|
||
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;
|
||
}
|
||
|
||
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 = __SERVER__ ? local : window.location.origin;
|
||
if (isDev) {
|
||
return `${local}${path}`
|
||
}else{
|
||
return `${prod}${path}`;
|
||
}
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
|
||
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}`;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
export function setImagesUrl(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}`:`${path}`;
|
||
}else{
|
||
if (!isdev2) {
|
||
return `/${path}`
|
||
}
|
||
return `${local}/${path}`;
|
||
//return isDev?`${testlocal}/${path}`:`/${path}`;
|
||
}
|
||
}
|
||
|
||
export function getUrl(path, goTest) {
|
||
// const local = 'http://172.20.32.202:8080'
|
||
// if (isDev) {
|
||
// return `${local}${path?path:''}`
|
||
// }
|
||
return `${path ? path: ''}`;
|
||
}
|
||
|
||
export function getZoneUrl(path) {
|
||
|
||
let settings = localStorage.chromesetting&&JSON.parse(localStorage.chromesetting);
|
||
let actionUrl = settings && settings.common.zone;
|
||
|
||
return `${actionUrl}${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;
|
||
}
|
||
}})
|
||
|
||
setTimeout(function () {
|
||
checkSubmitFlgs=false;
|
||
}, 2500);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
export function Railsgettimes() {
|
||
// railsgettimess(`${getUrl()}/api/main/first_stamp.json`);
|
||
// 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) {
|
||
return `${getUrl()}/api/attachments.json${isDev ?`${isDev ?`?debug=${window._debugType || 'admin'}` : ""}` : ""}`;
|
||
}
|
||
|
||
export function getUploadLogoActionUrl() {
|
||
return `${getUrl()}/api/resumes/logo.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`;
|
||
}
|
||
|
||
export function getUploadActionUrltwo(id) {
|
||
return `${getUrlmys()}/api/shixuns/${id}/upload_data_sets.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`
|
||
}
|
||
|
||
export function getUploadActionUrlthree() {
|
||
return `${getUrlmys()}/api/jupyters/import_with_tpm.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`
|
||
}
|
||
|
||
export function getupload_git_file(id) {
|
||
return `${getUrlmys()}/api/shixuns/${id}/upload_git_file.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`
|
||
}
|
||
|
||
|
||
export function getUploadActionUrlOfAuth(id) {
|
||
return `${getUrl()}/api/users/accounts/${id}/auth_attachment.json${isDev ?`?debug=${window._debugType || 'admin'}` : ""}`
|
||
}
|
||
|
||
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) {
|
||
return url;
|
||
}
|
||
|
||
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>)
|
||
}
|
||
|
||
|
||
|
||
export function turnbar(str){
|
||
let s = str;
|
||
if(s && s.length>0){
|
||
if(s.indexOf("%")>-1){
|
||
s = s.split('%').join('_25');
|
||
}
|
||
if(s.indexOf("#")>-1){
|
||
s = s.split('#').join('%23');
|
||
}
|
||
if(s.indexOf("/")>-1){
|
||
s = s.split('/').join('%2F');
|
||
}
|
||
}
|
||
return s;
|
||
}
|
||
export function returnbar(str){
|
||
let s = str;
|
||
if(s && s.length>0){
|
||
if(str.indexOf("_25")>-1){
|
||
s = s.split('_25').join('%');
|
||
}
|
||
if(s.indexOf("%23")>-1){
|
||
s = s.split('%23').join('#');
|
||
}
|
||
if(s.indexOf("%2F")>-1){
|
||
s = s.split('%2F').join('/');
|
||
}
|
||
}
|
||
return s;
|
||
}
|
||
|
||
// 手动添加/修改mate标签
|
||
export function addMeta(name, content){
|
||
if (__SERVER__) {
|
||
document = domObj.window.document
|
||
}
|
||
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) {
|
||
if (__SERVER__) {
|
||
document = domObj.window.document
|
||
}
|
||
// 服务端没有location
|
||
const host = window.location.host === 'null' || !window.location.host ? ssrHost : window.location.host
|
||
const origin = window.location.origin === 'null' || !window.location.origin ? ssrOrigin : window.location.origin
|
||
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;
|
||
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;
|
||
}
|
||
document.querySelector(`link[rel='canonical']`).href = origin + url;
|
||
}
|
||
|
||
export function setDefaultMeta() {
|
||
|
||
if (__SERVER__) {
|
||
document = domObj.window.document
|
||
}
|
||
document.querySelector(`title`).textContent = 'GitLink | 新一代开源创新服务平台';
|
||
document.querySelector(`meta[property='og:title']`).content = 'GitLink | 确实开源';
|
||
document.querySelector(`meta[property='og:url']`).content = 'https://GitLink.org.cn/';
|
||
document.querySelector(`meta[property='og:description']`).content = 'GitLink 是一个新一代的开源创新服务平台,提供分布式协作开发、流水线运维、代码分析等功能,基于 Git 打造分布式代码托管环境。';
|
||
document.querySelector(`meta[property='og:image:alt']`).content = 'GitLink | 确实开源';
|
||
document.querySelector('meta[name="Keywords"]').content= 'GitLink, git, 开源, 代码托管, 项目管理, 版本控制, 代码分享, 项目协作, 协同开发平台';
|
||
document.querySelector(`meta[name='description']`).content = 'GitLink 是一个新一代的开源创新服务平台,提供分布式协作开发、流水线运维、代码分析等功能,基于 Git 打造分布式代码托管环境。';
|
||
document.querySelector(`meta[name='go-import']`).content ='GitLink.org.cn git https://GitLink.org.cn';
|
||
document.querySelector(`meta[name='octolytics-dimension-user_login']`).content = 'GitLink';
|
||
document.querySelector(`meta[name='octolytics-dimension-repository_nwo']`).content = 'GitLink';
|
||
document.querySelector(`meta[name='octolytics-dimension-repository_network_root_nwo']`).content = 'GitLink';
|
||
document.querySelector(`link[rel='canonical']`).href = 'https://GitLink.org.cn';
|
||
} |