Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for infoBackground with a base url for proxy/cache #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const data = new Vue({
iframeSnippet: '',
saving: false,
networkType: 'default',
baseBackgroundUrl: 'http://127.0.0.1:8088/image-cache/x1000/',
};
},
});
Expand Down
45 changes: 45 additions & 0 deletions src/components/StartupScreen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
>
</div>
</div>
<div class="input-column">
<label for="welcome-background">Background URL</label>
<input
id="welcome-background"
v-model="backgroundUrl"
type="text"
:style="{'border-color': isValidBackground ? '' : '#f00'}"
@blur="updateBackground"
>
</div>
</div>
<!--
<div v-for="field in ZNCfields" :key="field">
Expand Down Expand Up @@ -122,18 +132,53 @@ function infoContent(defaultVal) {
export default {
name: 'StartupScreen',
props: ['localData'],
data() {
return {
backgroundUrl: '',
urlRegex: null,
};
},
computed: {
startupGreetingText: startupOption('greetingText', ''),
startupButtonText: startupOption('buttonText', ''),
startupInfoContent: infoContent(''),
startupShowChannel: startupOption('showChannel', true),
startupShowNick: startupOption('showNick', true),
startupShowPassword: startupOption('showPassword', true),
isValidBackground() {
if (!this.backgroundUrl) {
return true;
}
return this.isValidUrl(this.backgroundUrl);
},
},
methods: {
update() {
this.$emit('setConfig', { reload: true });
},
updateBackground() {
if (this.backgroundUrl && !this.isValidUrl(this.backgroundUrl)) {
// only return if the url is not empty and invalid
return;
}
const baseBackgroundUrl = this.localData.baseBackgroundUrl;
const startupOptions = this.localData.config.startupOptions;
const newUrl = this.backgroundUrl ? baseBackgroundUrl + this.backgroundUrl : '';
this.$set(startupOptions, 'infoBackground', newUrl);
this.update();
},
isValidUrl(url) {
if (!this.urlRegex) {
// regex from https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
this.urlRegex = new RegExp('^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
}
return this.urlRegex.test(url);
},
},
};
</script>