Skip to content

Commit

Permalink
Merge pull request #10 from ruibaby/fix/configmap
Browse files Browse the repository at this point in the history
fix: prevent page access issue when configmap is missing
  • Loading branch information
n0vad3v authored Jul 21, 2024
2 parents a57c51c + 113717e commit b89915f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

dependencies {
implementation platform('run.halo.tools.platform:plugin:2.13.0-SNAPSHOT')
implementation platform('run.halo.tools.platform:plugin:2.17.0-SNAPSHOT')
compileOnly 'run.halo.app:api'

testImplementation 'run.halo.app:api'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public Mono<Void> writeWith(@NonNull Publisher<? extends DataBuffer> body) {
var html = byteBuffersToString(byteBuffers);

return Settings.getBasicConfig(settingFetcher)
.switchIfEmpty(Mono.just(new Settings.BasicConfig()))
.flatMap(config -> {
var apiKeySecret = config.getApiKeySecret();
var proxies = config.getProxies();
Expand All @@ -125,15 +126,18 @@ public Mono<Void> writeWith(@NonNull Publisher<? extends DataBuffer> body) {

private String replaceImageSrc(String html, Proxy[] proxies) {
Document document = Jsoup.parse(html);
String externalUrl = externalUrlSupplier.get().toString();
var externalUrl = externalUrlSupplier.getRaw();

document.select("img").forEach(img -> {
String src = img.attr("src");

if (!PathUtils.isAbsoluteUri(src)) {
String proxyUrl = getProxyUrl(src, proxies, externalUrl);
if (proxyUrl != null) {
img.attr("src", proxyUrl + src);
if (externalUrl != null) {
String proxyUrl = getProxyUrl(proxies, externalUrl.toString());

if (proxyUrl != null) {
img.attr("src", proxyUrl + src);
}
}
} else {
for (Proxy proxy : proxies) {
Expand All @@ -148,7 +152,7 @@ private String replaceImageSrc(String html, Proxy[] proxies) {
return document.outerHtml();
}

private String getProxyUrl(String src, Proxy[] proxies, String externalUrl) {
private String getProxyUrl(Proxy[] proxies, String externalUrl) {
for (Proxy proxy : proxies) {
if (proxy.getOrigin_url().equals(externalUrl)) {
return proxy.getProxy_url();
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/ApiKeyBindingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ async function onSubmit(data: { apiKeySecret: string }) {
const configMapToCreate: ConfigMap = {
data: {
basic: JSON.stringify({
basic: { apiKeySecret: data.apiKeySecret, proxies: [] },
apiKeySecret: data.apiKeySecret,
proxies: [],
}),
},
apiVersion: "v1alpha1",
Expand Down

0 comments on commit b89915f

Please sign in to comment.