mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-03 14:33: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["destination_directory"] = "";
|
||||
stringValues["get_file_link"] = "";
|
||||
stringValues["modified_by"] = "";
|
||||
stringValues["get_o365_drive_id"] = "";
|
||||
stringValues["remove_directory"] = "";
|
||||
stringValues["single_directory"] = "";
|
||||
|
@ -388,6 +389,9 @@ final class Config
|
|||
"min-notify-changes",
|
||||
"Minimum number of pending incoming changes necessary to trigger a desktop notification",
|
||||
&longValues["min_notify_changes"],
|
||||
"modified-by",
|
||||
"Display the last modified by details of a given path",
|
||||
&stringValues["modified_by"],
|
||||
"monitor|m",
|
||||
"Keep monitoring for local and remote changes",
|
||||
&boolValues["monitor"],
|
||||
|
@ -721,6 +725,7 @@ void outputLongHelp(Option[] opt)
|
|||
"--get-O365-drive-id",
|
||||
"--log-dir",
|
||||
"--min-notify-changes",
|
||||
"--modified-by",
|
||||
"--monitor-interval",
|
||||
"--monitor-log-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
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -996,10 +996,19 @@ int main(string[] args)
|
|||
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") != "") {
|
||||
// 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
|
||||
// Use exit scopes to shutdown API
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -853,7 +853,7 @@ final class OneDriveApi
|
|||
checkAccessTokenExpired();
|
||||
const(char)[] url;
|
||||
url = driveByIdUrl ~ driveId ~ "/items/" ~ id;
|
||||
url ~= "?select=size,malware,file,webUrl";
|
||||
url ~= "?select=size,malware,file,webUrl,lastModifiedBy,lastModifiedDateTime";
|
||||
return get(url);
|
||||
}
|
||||
|
||||
|
|
38
src/sync.d
38
src/sync.d
|
@ -6104,8 +6104,8 @@ final class SyncEngine
|
|||
}
|
||||
}
|
||||
|
||||
// Query OneDrive for a URL path of a file
|
||||
void queryOneDriveForFileURL(string localFilePath, string syncDir)
|
||||
// Query OneDrive for file details of a given path
|
||||
void queryOneDriveForFileDetails(string localFilePath, string syncDir, string outputType)
|
||||
{
|
||||
// Query if file is valid locally
|
||||
if (exists(localFilePath)) {
|
||||
|
@ -6127,21 +6127,41 @@ final class SyncEngine
|
|||
displayOneDriveErrorMessage(e.msg, getFunctionName!({}));
|
||||
return;
|
||||
}
|
||||
|
||||
if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
|
||||
// Valid JSON object
|
||||
writeln(fileDetails["webUrl"].str);
|
||||
|
||||
// debug output of response
|
||||
log.vdebug("API Response: ", fileDetails);
|
||||
|
||||
// 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) {
|
||||
// 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 {
|
||||
// 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