Skip to content

Commit f8626ef

Browse files
authored
refine google scope changes and allow existing links to continue work
1 parent 66ed16c commit f8626ef

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

DriveBackup/src/main/java/ratismal/drivebackup/config/configSections/BackupMethods.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,13 @@ public BackupMethods(GoogleDriveBackupMethod googleDrive, OneDriveBackupMethod o
148148
@NotNull
149149
@Contract ("_, _ -> new")
150150
public static BackupMethods parse(@NotNull FileConfiguration config, Logger logger) {
151+
String googleSharedDriveId = config.getString("googledrive.shared-drive-id").trim();
152+
if (!Strings.isNullOrEmpty(googleSharedDriveId)) {
153+
logger.log(intl("shared-drive-deprecated"));
154+
}
151155
GoogleDriveBackupMethod googleDriveMethod = new GoogleDriveBackupMethod(
152156
config.getBoolean("googledrive.enabled"),
153-
config.getString("googledrive.shared-drive-id").trim()
157+
googleSharedDriveId
154158
);
155159
OneDriveBackupMethod oneDriveMethod = new OneDriveBackupMethod(
156160
config.getBoolean("onedrive.enabled")

DriveBackup/src/main/java/ratismal/drivebackup/handler/CommandTabComplete.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ public List<String> onTabComplete(CommandSender player, @NotNull Command cmd, St
4141
List<String> commandList = new ArrayList<>(10);
4242
commandList.add("v");
4343
commandList.add("help");
44+
commandList.add("commands");
4445
if (hasPerm(player, Permission.LINK_ACCOUNTS)) {
4546
commandList.add("linkaccount");
47+
commandList.add("unlinkaccount");
4648
}
4749
if (hasPerm(player, Permission.RELOAD_CONFIG)) {
4850
commandList.add("reloadconfig");
49-
}
50-
if (hasPerm(player, Permission.RELOAD_CONFIG)) {
5151
commandList.add("debug");
5252
}
5353
if (hasPerm(player, Permission.GET_BACKUP_STATUS)) {
@@ -58,11 +58,7 @@ public List<String> onTabComplete(CommandSender player, @NotNull Command cmd, St
5858
}
5959
if (hasPerm(player, Permission.BACKUP)) {
6060
commandList.add("backup");
61-
}
62-
if (hasPerm(player, Permission.BACKUP)) {
6361
commandList.add("test");
64-
}
65-
if (hasPerm(player, Permission.BACKUP)) {
6662
commandList.add("update");
6763
}
6864
return commandList;

DriveBackup/src/main/java/ratismal/drivebackup/uploaders/googledrive/GoogleDriveUploader.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import com.google.api.client.auth.oauth2.BearerToken;
44
import com.google.api.client.auth.oauth2.Credential;
5+
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
56
import com.google.api.client.http.FileContent;
67
import com.google.api.client.http.HttpRequestInitializer;
78
import com.google.api.client.http.HttpTransport;
89
import com.google.api.client.http.javanet.NetHttpTransport;
910
import com.google.api.client.json.JsonFactory;
1011
import com.google.api.client.json.jackson2.JacksonFactory;
12+
import com.google.api.client.util.Strings;
1113
import com.google.api.services.drive.Drive;
1214
import com.google.api.services.drive.model.ChildList;
1315
import com.google.api.services.drive.model.ChildReference;
@@ -85,6 +87,13 @@ public GoogleDriveUploader(UploadLogger logger) {
8587
try {
8688
refreshToken = Authenticator.getRefreshToken(AuthenticationProvider.GOOGLE_DRIVE);
8789
retrieveNewAccessToken();
90+
String sharedDriveId = ConfigParser.getConfig().backupMethods.googleDrive.sharedDriveId;
91+
if (!Strings.isNullOrEmpty(sharedDriveId)) {
92+
drives = service.drives().list().execute().getItems();
93+
}
94+
} catch (GoogleJsonResponseException e) {
95+
logger.log(intl("shared-drive-error"));
96+
setErrorOccurred(true);
8897
} catch (Exception e) {
8998
MessageUtil.sendConsoleException(e);
9099
setErrorOccurred(true);
@@ -221,7 +230,7 @@ public void uploadFile(java.io.File file, String type) {
221230
try {
222231
pruneBackups(folder);
223232
} catch (Exception e) {
224-
if (!sharedDriveId.isEmpty()) {
233+
if (!Strings.isNullOrEmpty(sharedDriveId)) {
225234
logger.log(intl("backup-method-shared-drive-prune-failed"));
226235
} else {
227236
logger.log(intl("backup-method-prune-failed"));

DriveBackup/src/main/resources/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ remote-save-directory: "backups"
3333

3434
googledrive:
3535
enabled: false
36-
shared-drive-id: ""
3736
onedrive:
3837
enabled: false
3938
dropbox:

DriveBackup/src/main/resources/intl.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ drivebackup-help-command: |-
105105
<gold><click:run_command:/drivebackup linkaccount onedrive>/drivebackup [unlink|unlinkaccount] onedrive</click></gold> - Unlinks your OneDrive account and disables method
106106
<gold><click:run_command:/drivebackup linkaccount dropbox>/drivebackup [unlink|unlinkaccount] dropbox</click></gold> - Unlinks your Dropbox account and disables method
107107
<gold><click:run_command:/drivebackup reloadconfig>/drivebackup reloadconfig</click></gold> - Reloads the config.yml
108+
<gold><click:run_command:/drivebackup debug>/drivebackup debug</click></gold> - Gathers useful info for troubleshooting the plugin
108109
<gold><click:run_command:/drivebackup nextbackup>/drivebackup nextbackup</click></gold> - Gets the time/date of the next auto backup
109110
<gold><click:run_command:/drivebackup status>/drivebackup status</click></gold> - Gets the status of the running backup
110111
<gold><click:run_command:/drivebackup backup>/drivebackup backup</click></gold> - Manually initiates a backup
@@ -214,6 +215,12 @@ player-join-update-available: |-
214215
An update is available, get it here: <gold><click:open_url:https://bit.ly/2M14uVD>https://bit.ly/2M14uVD</click></gold>
215216
or by running <gold><click:run_command:/drivebackup update>/drivebackup update</click></gold>
216217
plugin-stop: "Stopping plugin!"
218+
shared-drive-deprecated: |-
219+
Due to new restrictions from Google we are no longer able to support shared drives on new account links.
220+
Any existing links are able to continue to use this feature for now.
221+
shared-drive-error: |-
222+
An error has occurred while fetching your shared drive.
223+
Please ensure the shared-drive-id is correct or remove to continue using your personal drive."
217224
test-file-creation-failed: "Test file creation failed, please try again"
218225
test-method-begin: "Beginning the test on <upload-method>"
219226
test-method-failed: "The <upload-method> test was unsuccessful, please check the

0 commit comments

Comments
 (0)