dotnetdevs / synology Goto Github PK
View Code? Open in Web Editor NEWSynology Client for Build-In APIs for .NET Projects
Home Page: https://dotnetdevs.github.io/Synology/
License: Apache License 2.0
Synology Client for Build-In APIs for .NET Projects
Home Page: https://dotnetdevs.github.io/Synology/
License: Apache License 2.0
Following the README
, can you help describe where this test scenario has gone awry?
https://github.com/mitch-b/synology-forbidden-error-test
I've created an ASP.NET Core Web project that tries to connect to a Synology server configured in the appsettings.json
, and configured / executed in Startup.cs
for demo purposes.
Even if I attempt with valid credentials, I'm getting a Forbidden 403 error. I'm on DSM 6.1.5-15254 Update 1. I tried this on an account without two factor authentication enabled, but I also tried with another account sending OtpCode
as well. Still no success.
Thanks for any advice!
When trying to run your example code I get an exception on the line:
var resInfo = syno.Api().Info().GetInfo();
The exception says: DependencyResolutionException
None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Synology.Api.Info.InfoRequest' can be invoked with the available services and parameters:
Cannot resolve parameter 'Synology.Classes.SynologyApi api' of constructor 'Void .ctor(SynologyApi)'.
While debugging the StartAsync
extension from CopyMove()
method sending the StartParamters
it would only move a file if I caught the 'start' method and removed any brackets in the URL. When testing with a single files to copy/move (remove_src: true/false) the process would only move. Setting remove_src: false
would always result in a 'move'.
Note: The share name is a guid. Couldn't think of a name for testing and is not a weird glitch.
SynologyConnectionExtension.cs: Line 108
Addition starting after line 110:
if (method.Equals("start"))
url = url.Replace("[", "").Replace("]", "");
StartAsync(<StartParamters>)
:[HttpPost]
[Route("CopyMove")]
public async Task<IActionResult> CopyMove([FromBody] CopyMoveParams.StartParameters parameters)
{
ResultData<CopyMoveResults.IStartResult> start = new ResultData<CopyMoveResults.IStartResult>();
if (parameters.Path != null)
{
if (parameters.Path.Count() == 1)
{
using (var syno = _serviceProvider.GetService<ISynologyConnection>())
{
var login = await syno.Api().Auth().LoginAsync();
start = await syno.FileStation().CopyMove().StartAsync(parameters);
var logout = await syno.Api().Auth().LogoutAsync();
}
return Json(start);
}
else
{
return Json(new { Success = false, Error = "Only one copy/move instance is supported at this time." });
}
}
else
{
return Json(start);
}
}
Thanks,
-- Lincoln
All methods calling a Synology API must return an Interface and not the Library class implementation, it's useless and more secure.
Currently, the query parameters of the request was not be encoded, this may cause some bug if any parameter contains special chars like &
, or #
, etc.
When I create a download task, I have to manually encode the magnet link:
ServiceProvider.GetService<ISynologyConnection>()
.DownloadStation()
.Task()
.CreateAsync(new TaskCreateParameters{ Uri = System.Web.HttpUtility.UrlEncode(url) });
Hey, how am I supposed to do FileStation Upload if the IUploadRequest interface is empty?
While debugging the RenameAsync
extension sending the RenameParamters
it would only rename a file/directory if I caught the 'rename' method and removed any brackets in the URL. When testing with multiple files/directories to rename I would get the 408 error (No such file or directory).
To add there seems to be an additional issue when you do not set a additional
parameter. The below work around removes a zero addition parameter if there are no additional parameters.
Note: The share name is a guid. Couldn't think of a name for testing and is not a weird glitch.
SynologyConnectionExtension.cs: Line 108
Addition starting after line 110:
if (method.Equals("rename"))
url = url.Replace("&additional=[0]", "").Replace("[", "").Replace("]", "");
URL:
entry.cgi?path=/8c47db36-cce9-4fff-b4b2-a5df3a6a/example.txt,/8c47db36-cce9-4fff-b4b2-a5df3a6a/Folder A&name=test.txt,Folder B&additional=real_path&_sid=<MySID>&api=SYNO.FileStation.Rename&version=2&method=rename
Output:
{
"error": {
"code": 1200,
"errors": [
{
"code": 408,
"path": "/8c47db36-cce9-4fff-b4b2-a5df3a6a/example.txt,/8c47db36-cce9-4fff-b4b2-a5df3a6a/Folder A"
}
]
},
"success": false
}
RenameAsync(<RenameParamters>)
:[HttpPost]
[Route("Rename")]
public async Task<IActionResult> Rename([FromBody] RenameParameters parameters)
{
ResultData<RenameResult.IFileResult> renamed = new ResultData<RenameResult.IFileResult>();
if (parameters.Path != null && parameters.Name != null)
{
if (parameters.Additional == 0)
parameters.Additional = RenameAdditional.RealPath;
using (var syno = _serviceProvider.GetService<ISynologyConnection>())
{
var login = await syno.Api().Auth().LoginAsync();
renamed = await syno.FileStation().Rename().RenameAsync(parameters);
var logout = await syno.Api().Auth().LogoutAsync();
}
}
return Json(renamed);
}
This is an awesome code base for working with the Synology api! Been learning A TON just looking through the code. I hope the above reproduction and workaround is helpful to fix/help me. I tried figuring out how to fix this and do a pull request, but to be honest the code base is more sophisticated than I am capable of. The workaround is all I could come up with.
Thanks,
-- Lincoln
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.