1
0
Fork 0
mirror of https://gitlab.com/sbrl/GalleryShare.git synced 2018-06-12 22:45:16 +00:00

Fix file request wiring and pipe requests through to method

This commit is contained in:
Starbeamrainbowlabs 2016-07-08 09:50:53 +01:00
parent b05c64ce5b
commit 4f4ae8f4df

View file

@ -27,6 +27,11 @@ namespace GalleryShare
HttpListener server = new HttpListener();
string prefix;
Dictionary<string, string> pathReplacements = new Dictionary<string, string>()
{
{ "%20", " " }
};
public int Port { get { return port; } }
public string ServingDirectory { get { return servingDirectory; } }
@ -95,7 +100,7 @@ namespace GalleryShare
break;
case OutputFunction.SendFile:
await sendFile(requestedPath);
break;
default:
@ -109,7 +114,12 @@ namespace GalleryShare
private string GetFullReqestedPath(string rawUrl)
{
return Path.GetFullPath(Path.Combine(servingDirectory, "." + rawUrl));
string result = Path.GetFullPath(Path.Combine(servingDirectory, "." + rawUrl));
if(result.IndexOf("?") != -1)
result = result.Substring(0, result.IndexOf("?"));
foreach (KeyValuePair<string, string> replacePair in pathReplacements)
result = result.Replace(replacePair.Key, replacePair.Value);
return result;
}
private async Task sendMessage(HttpListenerContext cycle, int statusCode, string message, params object[] paramObjects)
@ -184,8 +194,13 @@ namespace GalleryShare
switch(specialFileName)
{
case "Transform-DirListing.xslt":
cycle.Response.ContentType = "text/xsl";
outputFileName = @"GalleryShare.Embed.DirectoryListing.xslt";
break;
case "Theme.css":
cycle.Response.ContentType = "text/css";
outputFileName = @"GalleryShare.Embed.Theme.css";
break;
}
if (outputFileName == string.Empty)
@ -197,14 +212,13 @@ namespace GalleryShare
/*string[] resNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
foreach (string resName in resNames)
Console.WriteLine(resName);*/
cycle.Response.ContentType = "text/xsl";
byte[] xsltData = await Utilities.GetEmbeddedResourceContent(outputFileName);
await cycle.Response.OutputStream.WriteAsync(xsltData, 0, xsltData.Length);
}
private async Task sendFile(string requestedPath)
{
Console.WriteLine("File requested: {0}", requestedPath);
}
}
}