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

Implement Backup Server Address #1586

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 config.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"serverAddress": "https://sponsor.ajay.app",
"backupServerAddress": "REPLACETHISWITHABACKUPSERVERURL",
"testingServerAddress": "https://sponsor.ajay.app/test",
"serverAddressComment": "This specifies the default SponsorBlock server to connect to",
"categoryList": ["sponsor", "selfpromo", "exclusive_access", "interaction", "poi_highlight", "intro", "outro", "preview", "filler", "chapter", "music_offtopic"],
Expand Down
6 changes: 6 additions & 0 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@
"customServerAddressDescription": {
"message": "The address SponsorBlock uses to make calls to the server.\nUnless you have your own server instance, this should not be changed."
},
"customBackupServerAddress": {
"message": "SponsorBlock Bacup Server Address"
},
"customBackupServerAddressDescription": {
"message": "The bacup address SponsorBlock uses to make calls to the server when the primariy Server is unavailable.\nUnless you have your own server instance, this should not be changed."
},
"save": {
"message": "Save"
},
Expand Down
20 changes: 20 additions & 0 deletions public/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,26 @@ <h2>__MSG_exportOptions__</h2>
</div>
</div>

<div data-type="text-change" data-sync="backupServerAddress">
<label class="optionLabel inline">
<span class="optionLabel">__MSG_customBackupServerAddress__:</span>

<input class="option-text-box" type="text" style="margin-right:10px">
</label>

<div class="small-description">__MSG_customBackupServerAddressDescription__</div>

<div class="next-line">
<div class="option-button text-change-set inline">
__MSG_save__
</div>

<div class="option-button text-change-reset inline">
__MSG_reset__
</div>
</div>
</div>

</div>

</div>
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface SBConfig {
invidiousInstances: string[];
supportInvidious: boolean;
serverAddress: string;
backupServerAddress: string;
minDuration: number;
skipNoticeDuration: number;
audioNotificationOnSkip: boolean;
Expand Down Expand Up @@ -181,6 +182,7 @@ const Config: SBObject = {
invidiousInstances: ["invidious.snopyta.org"], // leave as default
supportInvidious: false,
serverAddress: CompileConfig.serverAddress,
backupServerAddress: CompileConfig.backupServerAddress,
minDuration: 0,
skipNoticeDuration: 4,
audioNotificationOnSkip: false,
Expand Down
1 change: 1 addition & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ async function init() {
textChangeSetButton.addEventListener("click", async () => {
// See if anything extra must be done
switch (option) {
case "backupServerAddress":
case "serverAddress": {
const result = validateServerAddress(textChangeInput.value);

Expand Down
9 changes: 8 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,14 @@ export default class Utils {
async asyncRequestToServer(type: string, address: string, data = {}): Promise<FetchResponse> {
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;

return await (this.asyncRequestToCustomServer(type, serverAddress + address, data));
let response = await (this.asyncRequestToCustomServer(type, serverAddress + address, data));

if(response.status >= 500 && response.status <= 599 && Config.config.backupServerAddress != undefined && Config.config.backupServerAddress.replace(/\/+$/, "").startsWith("http"))
{
response = await (this.asyncRequestToCustomServer(type, Config.config.backupServerAddress + address, data));
}

return response;
}

/**
Expand Down