1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-08-17 00:31:42 +02:00
Files
.github
.idea
bld
lib
TweetLib.Browser
TweetLib.Browser.CEF
TweetLib.Communication
TweetLib.Core
Application
Features
Notifications
Plugins
TweetDeck
ISoundNotificationHandler.cs
ITweetDeckInterface.cs
TweetDeckBridgeObject.cs
TweetDeckBrowser.cs
TweetDeckExtraContext.cs
TweetDeckFunctions.cs
TweetDuckSchemeHandler.cs
VendorScriptProcessor.cs
Twitter
BaseBrowser.cs
BaseContextMenu.cs
BaseResourceRequestHandler.cs
CommonBridgeObject.cs
FileDownloadManager.cs
ICommonInterface.cs
PropertyObjectScript.cs
Resources
Systems
App.cs
Lib.cs
TweetLib.Core.csproj
TweetLib.Utils
TweetTest.Browser.CEF
TweetTest.Core
TweetTest.Utils
linux
resources
windows
.gitattributes
.gitignore
LICENSE.md
README.md
TweetDuck.sln
TweetDuck.sln.DotSettings
Version.cs
global.json

36 lines
1.2 KiB
C#

using System;
using System.Net;
using TweetLib.Browser.Interfaces;
using TweetLib.Browser.Request;
using TweetLib.Utils.Static;
namespace TweetLib.Core.Features.TweetDeck {
public sealed class TweetDuckSchemeHandler : ICustomSchemeHandler {
private static readonly SchemeResource InvalidUrl = new SchemeResource.Status(HttpStatusCode.NotFound, "Invalid URL.");
private static readonly SchemeResource PathMustBeRelativeToRoot = new SchemeResource.Status(HttpStatusCode.Forbidden, "File path has to be relative to the root folder.");
public string Protocol => "td";
private readonly ResourceCache resourceCache;
public TweetDuckSchemeHandler(ResourceCache resourceCache) {
this.resourceCache = resourceCache;
}
public SchemeResource Resolve(Uri uri) {
string? rootPath = uri.Authority switch {
"resources" => App.ResourcesPath,
"guide" => App.GuidePath,
_ => null
};
if (rootPath == null) {
return InvalidUrl;
}
string filePath = FileUtils.ResolveRelativePathSafely(rootPath, uri.AbsolutePath.TrimStart('/'));
return filePath.Length == 0 ? PathMustBeRelativeToRoot : resourceCache.ReadFile(filePath);
}
}
}