fix: local url used in share link instead of server url (#431)

fix: use explicitly Server Public URl in link sharing
This commit is contained in:
Tom 2026-02-10 01:02:15 -03:00 committed by GitHub
parent fb568d1d74
commit 3958cbcc1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 2 deletions

View file

@ -56,6 +56,48 @@ public class App extends Application {
return subsonic;
}
public static Subsonic getSubsonicPublicClientInstance(boolean override) {
/*
If I do the shortcut that the IDE suggests:
SubsonicPreferences preferences = getSubsonicPreferences1();
During the chain of calls it will run the following:
String server = Preferences.getInUseServerAddress();
Which could return Local URL, causing issues like generating public shares with Local URL
To prevent this I just replicated the entire chain of functions here,
if you need a call to Subsonic using the Server (Public) URL use this function.
*/
String server = Preferences.getServer();
String username = Preferences.getUser();
String password = Preferences.getPassword();
String token = Preferences.getToken();
String salt = Preferences.getSalt();
boolean isLowSecurity = Preferences.isLowScurity();
SubsonicPreferences preferences = new SubsonicPreferences();
preferences.setServerUrl(server);
preferences.setUsername(username);
preferences.setAuthentication(password, token, salt, isLowSecurity);
if (subsonic == null || override) {
if (preferences.getAuthentication() != null) {
if (preferences.getAuthentication().getPassword() != null)
Preferences.setPassword(preferences.getAuthentication().getPassword());
if (preferences.getAuthentication().getToken() != null)
Preferences.setToken(preferences.getAuthentication().getToken());
if (preferences.getAuthentication().getSalt() != null)
Preferences.setSalt(preferences.getAuthentication().getSalt());
}
}
return new Subsonic(preferences);
}
public static Github getGithubClientInstance() {
if (github == null) {
github = new Github();

View file

@ -41,7 +41,7 @@ public class SharingRepository {
public MutableLiveData<Share> createShare(String id, String description, Long expires) {
MutableLiveData<Share> share = new MutableLiveData<>();
App.getSubsonicClientInstance(false)
App.getSubsonicPublicClientInstance(false)
.getSharingClient()
.createShare(id, description, expires)
.enqueue(new Callback<ApiResponse>() {
@ -64,7 +64,7 @@ public class SharingRepository {
}
public void updateShare(String id, String description, Long expires) {
App.getSubsonicClientInstance(false)
App.getSubsonicPublicClientInstance(false)
.getSharingClient()
.updateShare(id, description, expires)
.enqueue(new Callback<ApiResponse>() {