mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-01 21:42:16 +02:00
Implement feature request --modified-by (#1869)
* Implement --modified-by to display who last modified a file and when the modification was done
This commit is contained in:
parent
8dc0723640
commit
3124b2dcf2
|
@ -286,6 +286,7 @@ final class Config
|
||||||
stringValues["create_share_link"] = "";
|
stringValues["create_share_link"] = "";
|
||||||
stringValues["destination_directory"] = "";
|
stringValues["destination_directory"] = "";
|
||||||
stringValues["get_file_link"] = "";
|
stringValues["get_file_link"] = "";
|
||||||
|
stringValues["modified_by"] = "";
|
||||||
stringValues["get_o365_drive_id"] = "";
|
stringValues["get_o365_drive_id"] = "";
|
||||||
stringValues["remove_directory"] = "";
|
stringValues["remove_directory"] = "";
|
||||||
stringValues["single_directory"] = "";
|
stringValues["single_directory"] = "";
|
||||||
|
@ -388,6 +389,9 @@ final class Config
|
||||||
"min-notify-changes",
|
"min-notify-changes",
|
||||||
"Minimum number of pending incoming changes necessary to trigger a desktop notification",
|
"Minimum number of pending incoming changes necessary to trigger a desktop notification",
|
||||||
&longValues["min_notify_changes"],
|
&longValues["min_notify_changes"],
|
||||||
|
"modified-by",
|
||||||
|
"Display the last modified by details of a given path",
|
||||||
|
&stringValues["modified_by"],
|
||||||
"monitor|m",
|
"monitor|m",
|
||||||
"Keep monitoring for local and remote changes",
|
"Keep monitoring for local and remote changes",
|
||||||
&boolValues["monitor"],
|
&boolValues["monitor"],
|
||||||
|
@ -721,6 +725,7 @@ void outputLongHelp(Option[] opt)
|
||||||
"--get-O365-drive-id",
|
"--get-O365-drive-id",
|
||||||
"--log-dir",
|
"--log-dir",
|
||||||
"--min-notify-changes",
|
"--min-notify-changes",
|
||||||
|
"--modified-by",
|
||||||
"--monitor-interval",
|
"--monitor-interval",
|
||||||
"--monitor-log-frequency",
|
"--monitor-log-frequency",
|
||||||
"--monitor-fullscan-frequency",
|
"--monitor-fullscan-frequency",
|
||||||
|
|
15
src/main.d
15
src/main.d
|
@ -726,7 +726,7 @@ int main(string[] args)
|
||||||
|
|
||||||
// create-directory, remove-directory, source-directory, destination-directory
|
// create-directory, remove-directory, source-directory, destination-directory
|
||||||
// these are activities that dont perform a sync, so to not generate an error message for these items either
|
// these are activities that dont perform a sync, so to not generate an error message for these items either
|
||||||
if (((cfg.getValueString("create_directory") != "") || (cfg.getValueString("remove_directory") != "")) || ((cfg.getValueString("source_directory") != "") && (cfg.getValueString("destination_directory") != "")) || (cfg.getValueString("get_file_link") != "") || (cfg.getValueString("create_share_link") != "") || (cfg.getValueString("get_o365_drive_id") != "") || cfg.getValueBool("display_sync_status") || cfg.getValueBool("list_business_shared_folders")) {
|
if (((cfg.getValueString("create_directory") != "") || (cfg.getValueString("remove_directory") != "")) || ((cfg.getValueString("source_directory") != "") && (cfg.getValueString("destination_directory") != "")) || (cfg.getValueString("get_file_link") != "") || (cfg.getValueString("modified_by") != "") || (cfg.getValueString("create_share_link") != "") || (cfg.getValueString("get_o365_drive_id") != "") || cfg.getValueBool("display_sync_status") || cfg.getValueBool("list_business_shared_folders")) {
|
||||||
performSyncOK = true;
|
performSyncOK = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -996,10 +996,19 @@ int main(string[] args)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we obtaining the URL path for a synced file?
|
// --get-file-link - Are we obtaining the URL path for a synced file?
|
||||||
if (cfg.getValueString("get_file_link") != "") {
|
if (cfg.getValueString("get_file_link") != "") {
|
||||||
// Query OneDrive for the file link
|
// Query OneDrive for the file link
|
||||||
sync.queryOneDriveForFileURL(cfg.getValueString("get_file_link"), syncDir);
|
sync.queryOneDriveForFileDetails(cfg.getValueString("get_file_link"), syncDir, "URL");
|
||||||
|
// Exit application
|
||||||
|
// Use exit scopes to shutdown API
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --modified-by - Are we listing the modified-by details of a provided path?
|
||||||
|
if (cfg.getValueString("modified_by") != "") {
|
||||||
|
// Query OneDrive for the file link
|
||||||
|
sync.queryOneDriveForFileDetails(cfg.getValueString("modified_by"), syncDir, "ModifiedBy");
|
||||||
// Exit application
|
// Exit application
|
||||||
// Use exit scopes to shutdown API
|
// Use exit scopes to shutdown API
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
@ -853,7 +853,7 @@ final class OneDriveApi
|
||||||
checkAccessTokenExpired();
|
checkAccessTokenExpired();
|
||||||
const(char)[] url;
|
const(char)[] url;
|
||||||
url = driveByIdUrl ~ driveId ~ "/items/" ~ id;
|
url = driveByIdUrl ~ driveId ~ "/items/" ~ id;
|
||||||
url ~= "?select=size,malware,file,webUrl";
|
url ~= "?select=size,malware,file,webUrl,lastModifiedBy,lastModifiedDateTime";
|
||||||
return get(url);
|
return get(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
36
src/sync.d
36
src/sync.d
|
@ -6104,8 +6104,8 @@ final class SyncEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query OneDrive for a URL path of a file
|
// Query OneDrive for file details of a given path
|
||||||
void queryOneDriveForFileURL(string localFilePath, string syncDir)
|
void queryOneDriveForFileDetails(string localFilePath, string syncDir, string outputType)
|
||||||
{
|
{
|
||||||
// Query if file is valid locally
|
// Query if file is valid locally
|
||||||
if (exists(localFilePath)) {
|
if (exists(localFilePath)) {
|
||||||
|
@ -6128,20 +6128,40 @@ final class SyncEngine
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
|
// debug output of response
|
||||||
// Valid JSON object
|
log.vdebug("API Response: ", fileDetails);
|
||||||
writeln(fileDetails["webUrl"].str);
|
|
||||||
|
// What sort of response to we generate
|
||||||
|
// --get-file-link response
|
||||||
|
if (outputType == "URL") {
|
||||||
|
if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
|
||||||
|
// Valid JSON object
|
||||||
|
writeln(fileDetails["webUrl"].str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --modified-by response
|
||||||
|
if (outputType == "ModifiedBy") {
|
||||||
|
if ((fileDetails.type() == JSONType.object) && ("lastModifiedBy" in fileDetails)) {
|
||||||
|
// Valid JSON object
|
||||||
|
writeln("Last modified: ", fileDetails["lastModifiedDateTime"].str);
|
||||||
|
writeln("Last modified by: ", fileDetails["lastModifiedBy"]["user"]["displayName"].str);
|
||||||
|
// if 'email' provided, add this to the output
|
||||||
|
if ("email" in fileDetails["lastModifiedBy"]["user"]) {
|
||||||
|
writeln("Email Address: ", fileDetails["lastModifiedBy"]["user"]["email"].str);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// was file found?
|
// was path found?
|
||||||
if (!fileInDB) {
|
if (!fileInDB) {
|
||||||
// File has not been synced with OneDrive
|
// File has not been synced with OneDrive
|
||||||
log.error("File has not been synced with OneDrive: ", localFilePath);
|
log.error("Path has not been synced with OneDrive: ", localFilePath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// File does not exist locally
|
// File does not exist locally
|
||||||
log.error("File not found on local system: ", localFilePath);
|
log.error("Path not found on local system: ", localFilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue