Skip to content

Commit

Permalink
refine google scope changes and allow existing links to continue work
Browse files Browse the repository at this point in the history
  • Loading branch information
rhld16 authored Aug 8, 2024
1 parent 66ed16c commit f8626ef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ public BackupMethods(GoogleDriveBackupMethod googleDrive, OneDriveBackupMethod o
@NotNull
@Contract ("_, _ -> new")
public static BackupMethods parse(@NotNull FileConfiguration config, Logger logger) {
String googleSharedDriveId = config.getString("googledrive.shared-drive-id").trim();
if (!Strings.isNullOrEmpty(googleSharedDriveId)) {
logger.log(intl("shared-drive-deprecated"));
}
GoogleDriveBackupMethod googleDriveMethod = new GoogleDriveBackupMethod(
config.getBoolean("googledrive.enabled"),
config.getString("googledrive.shared-drive-id").trim()
googleSharedDriveId
);
OneDriveBackupMethod oneDriveMethod = new OneDriveBackupMethod(
config.getBoolean("onedrive.enabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public List<String> onTabComplete(CommandSender player, @NotNull Command cmd, St
List<String> commandList = new ArrayList<>(10);
commandList.add("v");
commandList.add("help");
commandList.add("commands");
if (hasPerm(player, Permission.LINK_ACCOUNTS)) {
commandList.add("linkaccount");
commandList.add("unlinkaccount");
}
if (hasPerm(player, Permission.RELOAD_CONFIG)) {
commandList.add("reloadconfig");
}
if (hasPerm(player, Permission.RELOAD_CONFIG)) {
commandList.add("debug");
}
if (hasPerm(player, Permission.GET_BACKUP_STATUS)) {
Expand All @@ -58,11 +58,7 @@ public List<String> onTabComplete(CommandSender player, @NotNull Command cmd, St
}
if (hasPerm(player, Permission.BACKUP)) {
commandList.add("backup");
}
if (hasPerm(player, Permission.BACKUP)) {
commandList.add("test");
}
if (hasPerm(player, Permission.BACKUP)) {
commandList.add("update");
}
return commandList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.Strings;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.ChildList;
import com.google.api.services.drive.model.ChildReference;
Expand Down Expand Up @@ -85,6 +87,13 @@ public GoogleDriveUploader(UploadLogger logger) {
try {
refreshToken = Authenticator.getRefreshToken(AuthenticationProvider.GOOGLE_DRIVE);
retrieveNewAccessToken();
String sharedDriveId = ConfigParser.getConfig().backupMethods.googleDrive.sharedDriveId;
if (!Strings.isNullOrEmpty(sharedDriveId)) {
drives = service.drives().list().execute().getItems();
}
} catch (GoogleJsonResponseException e) {
logger.log(intl("shared-drive-error"));
setErrorOccurred(true);
} catch (Exception e) {
MessageUtil.sendConsoleException(e);
setErrorOccurred(true);
Expand Down Expand Up @@ -221,7 +230,7 @@ public void uploadFile(java.io.File file, String type) {
try {
pruneBackups(folder);
} catch (Exception e) {
if (!sharedDriveId.isEmpty()) {
if (!Strings.isNullOrEmpty(sharedDriveId)) {
logger.log(intl("backup-method-shared-drive-prune-failed"));
} else {
logger.log(intl("backup-method-prune-failed"));
Expand Down
1 change: 0 additions & 1 deletion DriveBackup/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ remote-save-directory: "backups"

googledrive:
enabled: false
shared-drive-id: ""
onedrive:
enabled: false
dropbox:
Expand Down
7 changes: 7 additions & 0 deletions DriveBackup/src/main/resources/intl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ drivebackup-help-command: |-
<gold><click:run_command:/drivebackup linkaccount onedrive>/drivebackup [unlink|unlinkaccount] onedrive</click></gold> - Unlinks your OneDrive account and disables method
<gold><click:run_command:/drivebackup linkaccount dropbox>/drivebackup [unlink|unlinkaccount] dropbox</click></gold> - Unlinks your Dropbox account and disables method
<gold><click:run_command:/drivebackup reloadconfig>/drivebackup reloadconfig</click></gold> - Reloads the config.yml
<gold><click:run_command:/drivebackup debug>/drivebackup debug</click></gold> - Gathers useful info for troubleshooting the plugin
<gold><click:run_command:/drivebackup nextbackup>/drivebackup nextbackup</click></gold> - Gets the time/date of the next auto backup
<gold><click:run_command:/drivebackup status>/drivebackup status</click></gold> - Gets the status of the running backup
<gold><click:run_command:/drivebackup backup>/drivebackup backup</click></gold> - Manually initiates a backup
Expand Down Expand Up @@ -214,6 +215,12 @@ player-join-update-available: |-
An update is available, get it here: <gold><click:open_url:https://bit.ly/2M14uVD>https://bit.ly/2M14uVD</click></gold>
or by running <gold><click:run_command:/drivebackup update>/drivebackup update</click></gold>
plugin-stop: "Stopping plugin!"
shared-drive-deprecated: |-
Due to new restrictions from Google we are no longer able to support shared drives on new account links.
Any existing links are able to continue to use this feature for now.
shared-drive-error: |-
An error has occurred while fetching your shared drive.
Please ensure the shared-drive-id is correct or remove to continue using your personal drive."
test-file-creation-failed: "Test file creation failed, please try again"
test-method-begin: "Beginning the test on <upload-method>"
test-method-failed: "The <upload-method> test was unsuccessful, please check the
Expand Down

0 comments on commit f8626ef

Please sign in to comment.