Skip to content

Commit

Permalink
feat:更新基础版本
Browse files Browse the repository at this point in the history
  • Loading branch information
guicaiyue committed Mar 12, 2024
1 parent bcb3bd9 commit 48590a8
Show file tree
Hide file tree
Showing 25 changed files with 5,341 additions and 126 deletions.
510 changes: 510 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ application-local.yml
application-local.yaml
application-local.properties

/admin-frontend/node_modules/
/ui/node_modules/
/workplace/
/src/main/resources/console/
60 changes: 36 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
plugins {
id "com.github.node-gradle.node" version "3.3.0"
id "io.github.guqing.plugin-development" version "0.0.6-SNAPSHOT"
id 'java'
id "com.github.node-gradle.node" version "5.0.0"
id "io.freefair.lombok" version "8.0.1"
id "run.halo.plugin.devtools" version "0.0.7"
}

group 'run.halo.githuboss'
Expand All @@ -10,37 +11,48 @@ compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'

repositories {
mavenCentral()
maven { url 'https://s01.oss.sonatype.org/content/repositories/releases' }
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://repo.spring.io/milestone' }
mavenCentral()
}

jar {
enabled = true
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest.attributes(
'Plugin-Version': "${project.version}",
)
from {
configurations.runtimeClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
}
dependencies {
implementation platform('run.halo.tools.platform:plugin:2.11.0-SNAPSHOT')
compileOnly 'run.halo.app:api'

testImplementation 'run.halo.app:api'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'cn.hutool:hutool-json:5.8.26'
}

dependencies {
compileOnly platform("run.halo.dependencies:halo-dependencies:1.0.0")
test {
useJUnitPlatform()
}

compileOnly files("lib/halo-2.0.0-SNAPSHOT-plain.jar")
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}

compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
node {
nodeProjectDir = file("${project.projectDir}/ui")
}

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
implementation 'cn.hutool:hutool-json:5.8.16'
task buildFrontend(type: PnpmTask) {
args = ['build']
}

test {
useJUnitPlatform()
build {
// build frontend before build
tasks.getByName('compileJava').dependsOn('buildFrontend')
}

halo {
version = '2.13'
superAdminUsername = 'admin'
superAdminPassword = 'admin'
externalUrl = 'http://localhost:8098'
port = 8098
debug = true
debugPort = 5005
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Wed May 10 13:57:01 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
178 changes: 89 additions & 89 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
set JAVA_HOME=E:\jdk\jdk-17
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
set JAVA_HOME=E:\jdk\jdk-17
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
Binary file removed lib/halo-2.0.0-SNAPSHOT-plain.jar
Binary file not shown.
4 changes: 0 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
pluginManagement {
repositories {
maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/spring-plugin' }
maven { url 'https://repo.spring.io/milestone' }
gradlePluginPortal()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
enabled: true
# 'version' is a valid semantic version string (see semver.org).
version: 1.0.3
requires: ">=2.0.0"
requires: ">=2.11.0"
author:
name: xirizhi
website: https://guicai.work
Expand Down
82 changes: 81 additions & 1 deletion src/main/resources/static/plugin-githuboss-min.js
Original file line number Diff line number Diff line change
@@ -1 +1,81 @@
!function(){const t="githuboss_githubFastHttps",e=/(http.*jsdelivr.net)/g,n=["https://gcore.jsdelivr.net","https://cdn.jsdelivr.net","https://fastly.jsdelivr.net","https://originfastly.jsdelivr.net","https://quantil.jsdelivr.net"],a=(t,e,n)=>{const a=((t,e)=>t.getAttribute(e))(t,e);a&&a.match(/^http.*jsdelivr\.net/i)&&t.setAttribute(e,s(a,n))},r=async t=>{const e=await Promise.all(t.map((t=>(async t=>{const e=performance.now(),n=`${t}/gh/guicaiyue/FigureBed/Pwa/favicon.ico`;return await fetch(n,{mode:"no-cors"}),performance.now()-e})(t)))),n=Math.min(...e);return t[e.indexOf(n)]},s=(t,n)=>t.replace(e,n),i=()=>{let e=localStorage.getItem(t),s=-1!==n.indexOf(e)?e:/\s*zh-(CN|cn)\s*/g.test(navigator.language||navigator.browserLanguage||navigator.userLanguage)?"https://gcore.jsdelivr.net":"https://cdn.jsdelivr.net",i=document.getElementsByTagName("img");for(let t=0;t<i.length;t++)a(i[t],"src",s),a(i[t],"data-src",s);r(n).then((e=>{return n=e,localStorage.setItem(t,n);var n}))};document.addEventListener("DOMContentLoaded",(function(){i()}))}();
(function () {
// 立即执行函数开始
const githubFastHttpsKey = "githuboss_githubFastHttps";
const imgRegex = /(http.*jsdelivr.net)/g;
const testFilePath = "/gh/guicaiyue/FigureBed/Pwa/favicon.ico";
const domains = [
"https://gcore.jsdelivr.net",
"https://cdn.jsdelivr.net",
"https://fastly.jsdelivr.net",
"https://originfastly.jsdelivr.net",
"https://quantil.jsdelivr.net",
];

// 获取本地缓存的值
const getLocalValue = () => localStorage.getItem(githubFastHttpsKey);

// 设置本地缓存的值
const setLocalValue = (value) => localStorage.setItem(githubFastHttpsKey, value);

// 根据浏览器设置的语言判断用户是否在中国
const isInChina = () => {
const chinaRegexp = /\s*zh-(CN|cn)\s*/g;
return chinaRegexp.test(navigator.language || navigator.browserLanguage || navigator.userLanguage);
};

// 获取图片的指定属性地址
const getImageSrc = (imgElement,attribute) => imgElement.getAttribute(attribute);

// 替换图片的指定属性地址
const replaceImageSrc = (imgElement,attribute, domain) => {
const src = getImageSrc(imgElement,attribute);
if (src && src.match(/^http.*jsdelivr\.net/i)) {
imgElement.setAttribute(attribute, replaceImageProtocolAndDomain(src, domain));
}
}

// 测试哪个域名速度最快
const testDomainSpeed = async (domain) => {
try {
const startTime = performance.now();
const url = `${domain}${testFilePath}`;
const response = await fetch(url, {mode: "no-cors"});
const endTime = performance.now();
return endTime - startTime;
}catch (e) {
return 9999999;
}
};

// 获取最快的域名
const getFastestDomain = async (domains) => {
const domainSpeeds = await Promise.all(domains.map((domain) => testDomainSpeed(domain)));
const minSpeed = Math.min(...domainSpeeds);
const index = domainSpeeds.indexOf(minSpeed);
return domains[index];
};

// 替换图片地址的协议和域名
const replaceImageProtocolAndDomain = (imgSrc, domain) => {
return imgSrc.replace(imgRegex, domain);
};

// 初始化操作
const init = () => {
// 第一步,从本地缓存中获取 githubFastHttps 的值,如果不存在,则根据用户所在地区设置不同的值,并将其设置到本地缓存中
let githubFastHttps = getLocalValue();
let domain = domains.indexOf(githubFastHttps) !== -1 ? githubFastHttps : isInChina()? "https://gcore.jsdelivr.net":"https://cdn.jsdelivr.net";

// 第二步,替换页面中所有http.*jsdelivr.net的图片路径
let imgList = document.getElementsByTagName('img');
for (let i = 0; i < imgList.length; i++) {
replaceImageSrc(imgList[i],"src",domain);
replaceImageSrc(imgList[i],"data-src",domain);
}
// 第三步 异步更新最快的访问地址
getFastestDomain(domains).then(r => setLocalValue(r));
};
document.addEventListener("DOMContentLoaded", function () {
init();
});
})();
Loading

0 comments on commit 48590a8

Please sign in to comment.