mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-02 22:13:16 +02:00
Implement --get-file-link (#612)
* Implement --get-file-link which will return the weburl of a file which has been synced to OneDrive
This commit is contained in:
parent
a59490a79e
commit
4e97f8810d
|
@ -510,6 +510,8 @@ Options:
|
|||
Force the use of HTTP/2 for all operations where applicable
|
||||
--get-O365-drive-id ARG
|
||||
Query and return the Office 365 Drive ID for a given Office 365 SharePoint Shared Library
|
||||
--get-file-link ARG
|
||||
Display the file link of a synced file
|
||||
--help -h
|
||||
This help information.
|
||||
--local-first
|
||||
|
|
|
@ -91,6 +91,9 @@ Configuration file key: \fBforce_http_2\fP (default: \fBfalse\fP)
|
|||
\fB\-\-get\-O365\-drive\-id\fP ARG
|
||||
Query and return the Office 365 Drive ID for a given Office 365 SharePoint Shared Library
|
||||
.TP
|
||||
\fB\-\-get\-file\-link\fP ARG
|
||||
Display the file link of a synced file
|
||||
.TP
|
||||
\fB\-\-local\-first\fP
|
||||
Synchronize from the local directory source first, before downloading changes from OneDrive.
|
||||
.br
|
||||
|
|
|
@ -40,7 +40,7 @@ final class Config
|
|||
boolValues["disable_upload_validation"] = false;
|
||||
boolValues["enable_logging"] = false;
|
||||
boolValues["force_http_11"] = false;
|
||||
boolValues["force_http_2"] = false;
|
||||
boolValues["force_http_2"] = false;
|
||||
boolValues["local_first"] = false;
|
||||
boolValues["no_remote_delete"] = false;
|
||||
boolValues["skip_symlinks"] = false;
|
||||
|
@ -148,6 +148,7 @@ final class Config
|
|||
// Add additional options that are NOT configurable via config file
|
||||
stringValues["create_directory"] = "";
|
||||
stringValues["destination_directory"] = "";
|
||||
stringValues["get_file_link"] = "";
|
||||
stringValues["get_o365_drive_id"] = "";
|
||||
stringValues["remove_directory"] = "";
|
||||
stringValues["single_directory"] = "";
|
||||
|
@ -216,6 +217,9 @@ final class Config
|
|||
"force-http-2",
|
||||
"Force the use of HTTP/2 for all operations where applicable",
|
||||
&boolValues["force_http_2"],
|
||||
"get-file-link",
|
||||
"Display the file link of a synced file",
|
||||
&stringValues["get_file_link"],
|
||||
"get-O365-drive-id",
|
||||
"Query and return the Office 365 Drive ID for a given Office 365 SharePoint Shared Library",
|
||||
&stringValues["get_o365_drive_id"],
|
||||
|
|
14
src/main.d
14
src/main.d
|
@ -234,7 +234,7 @@ int main(string[] args)
|
|||
|
||||
// create-directory, remove-directory, source-directory, destination-directory
|
||||
// are activities that dont perform a sync no 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_o365_drive_id") != "") || cfg.getValueBool("display_sync_status")) {
|
||||
if (((cfg.getValueString("create_directory") != "") || (cfg.getValueString("remove_directory") != "")) || ((cfg.getValueString("source_directory") != "") && (cfg.getValueString("destination_directory") != "")) || (cfg.getValueString("get_file_link") != "") || (cfg.getValueString("get_o365_drive_id") != "") || cfg.getValueBool("display_sync_status")) {
|
||||
performSyncOK = true;
|
||||
}
|
||||
|
||||
|
@ -314,7 +314,10 @@ int main(string[] args)
|
|||
selectiveSync.setFileMask(cfg.getValueString("skip_file"));
|
||||
|
||||
// Initialize the sync engine
|
||||
log.logAndNotify("Initializing the Synchronization Engine ...");
|
||||
if (cfg.getValueString("get_file_link") == "") {
|
||||
// Print out that we are initializing the engine only if we are not grabbing the file link
|
||||
log.logAndNotify("Initializing the Synchronization Engine ...");
|
||||
}
|
||||
auto sync = new SyncEngine(cfg, oneDrive, itemDb, selectiveSync);
|
||||
|
||||
try {
|
||||
|
@ -367,10 +370,15 @@ int main(string[] args)
|
|||
}
|
||||
|
||||
// Are we obtaining the Office 365 Drive ID for a given Office 365 SharePoint Shared Library?
|
||||
if (cfg.getValueString("get_o365_drive_id") != ""){
|
||||
if (cfg.getValueString("get_o365_drive_id") != "") {
|
||||
sync.querySiteCollectionForDriveID(cfg.getValueString("get_o365_drive_id"));
|
||||
}
|
||||
|
||||
// Are we obtaining the URL path for a synced file?
|
||||
if (cfg.getValueString("get_file_link") != "") {
|
||||
sync.queryOneDriveForFileURL(cfg.getValueString("get_file_link"), syncDir);
|
||||
}
|
||||
|
||||
// Are we displaying the sync status of the client?
|
||||
if (cfg.getValueBool("display_sync_status")) {
|
||||
string remotePath = "/";
|
||||
|
|
|
@ -320,7 +320,7 @@ final class OneDriveApi
|
|||
const(char)[] url;
|
||||
// string driveByIdUrl = "https://graph.microsoft.com/v1.0/drives/";
|
||||
url = driveByIdUrl ~ driveId ~ "/items/" ~ id;
|
||||
url ~= "?select=size,malware,file";
|
||||
url ~= "?select=size,malware,file,webUrl";
|
||||
return get(url);
|
||||
}
|
||||
|
||||
|
|
32
src/sync.d
32
src/sync.d
|
@ -2635,6 +2635,38 @@ final class SyncEngine
|
|||
}
|
||||
}
|
||||
|
||||
// Query OneDrive for a URL path of a file
|
||||
void queryOneDriveForFileURL(string localFilePath, string syncDir) {
|
||||
// Query if file is valid locally
|
||||
if (exists(localFilePath)) {
|
||||
// File exists locally, does it exist in the database
|
||||
// Path needs to be relative to sync_dir path
|
||||
string relativePath = relativePath(localFilePath, syncDir);
|
||||
Item item;
|
||||
if (itemdb.selectByPath(relativePath, defaultDriveId, item)) {
|
||||
// File is in the local database cache
|
||||
JSONValue fileDetails;
|
||||
|
||||
try {
|
||||
fileDetails = onedrive.getFileDetails(item.driveId, item.id);
|
||||
} catch (OneDriveException e) {
|
||||
log.error("ERROR: Query of OneDrive for file details failed");
|
||||
}
|
||||
|
||||
if ((fileDetails.type() == JSONType.object) && ("webUrl" in fileDetails)) {
|
||||
// Valid JSON object
|
||||
writeln(fileDetails["webUrl"].str);
|
||||
}
|
||||
} else {
|
||||
// File has not been synced with OneDrive
|
||||
log.error("File has not been synced with OneDrive: ", localFilePath);
|
||||
}
|
||||
} else {
|
||||
// File does not exist locally
|
||||
log.error("File not found on local system: ", localFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
// Query the OneDrive 'drive' to determine if we are 'in sync' or if there are pending changes
|
||||
void queryDriveForChanges(string path) {
|
||||
|
||||
|
|
Loading…
Reference in a new issue