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

Add preliminary file sending.\nThumbnail generation doesn't work yet (see http://stackoverflow.com/q/38271118/1460422).

This commit is contained in:
Starbeamrainbowlabs 2016-07-08 17:12:57 +01:00
parent 4f4ae8f4df
commit 620cf2f892
4 changed files with 41 additions and 24 deletions

View file

@ -21,12 +21,14 @@
<xsl:template match="ListingEntry[@Type='File']">
<figure class='preview file'>
<img src="{Name}?thumbnail" />
<img src="{Name}?type=thumbnail" />
<figcaption><xsl:value-of select="Name" /></figcaption>
</figure>
</xsl:template>
<xsl:template match="ListingEntry[@Type='Directory']">
<figure class='preview directory'>
(coming soon)
<figcaption><xsl:value-of select="Name" /></figcaption>
</figure>
</xsl:template>
</xsl:stylesheet>

View file

@ -9,6 +9,8 @@ using System.Threading;
using System.Xml;
using System.Reflection;
using ImageMagick;
namespace GalleryShare
{
enum OutputFunction
@ -21,8 +23,12 @@ namespace GalleryShare
class GalleryServer
{
static MimeSharp.Mime mimeDB = new MimeSharp.Mime();
int port;
string servingDirectory = Environment.CurrentDirectory;
int thumbnailWidth = 300;
int thumbnailHeight = 200;
HttpListener server = new HttpListener();
string prefix;
@ -100,7 +106,7 @@ namespace GalleryShare
break;
case OutputFunction.SendFile:
await sendFile(requestedPath);
await sendFile(cycle, requestedPath);
break;
default:
@ -216,9 +222,26 @@ namespace GalleryShare
await cycle.Response.OutputStream.WriteAsync(xsltData, 0, xsltData.Length);
}
private async Task sendFile(string requestedPath)
private async Task sendFile(HttpListenerContext cycle, string requestedPath)
{
Console.WriteLine("File requested: {0}", requestedPath);
if(cycle.Request.QueryString["type"] == "thumbnail")
{
// Send a thumbnail!
MagickImage img = new MagickImage(requestedPath);
img.Thumbnail(new MagickGeometry(thumbnailWidth, thumbnailHeight));
cycle.Response.ContentType = "image/webp";
img.Write(cycle.Response.OutputStream, MagickFormat.WebP);
img.Dispose();
return;
}
// Send the raw file
cycle.Response.ContentType = mimeDB.Lookup(requestedPath);
Stream fileData = File.OpenRead(requestedPath);
await fileData.CopyToAsync(cycle.Response.OutputStream);
}
}
}

View file

@ -8,8 +8,6 @@
<RootNamespace>GalleryShare</RootNamespace>
<AssemblyName>GalleryShare</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
@ -35,6 +33,13 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="MimeSharp">
<HintPath>packages\MimeSharp.1.0.0\lib\MimeSharp.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="Magick.NET-Q16-AnyCPU">
<HintPath>..\packages\Magick.NET-Q16-AnyCPU.7.0.2.100\lib\net40-client\Magick.NET-Q16-AnyCPU.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
@ -43,10 +48,14 @@
<Compile Include="Utilities.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="packages\Magick.NET-Q8-x64.7.0.2.100\build\net40-client\Magick.NET-Q8-x64.targets" Condition="Exists('packages\Magick.NET-Q8-x64.7.0.2.100\build\net40-client\Magick.NET-Q8-x64.targets')" />
<ItemGroup>
<Folder Include="Embed\**" />
<Folder Include="Embed\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Embed\**" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
</Project>

View file

@ -1,17 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GalleryShare", "GalleryShare.csproj", "{806258ED-F088-44A1-A6BE-2B8E4D1007E5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{806258ED-F088-44A1-A6BE-2B8E4D1007E5}.Debug|x86.ActiveCfg = Debug|x86
{806258ED-F088-44A1-A6BE-2B8E4D1007E5}.Debug|x86.Build.0 = Debug|x86
{806258ED-F088-44A1-A6BE-2B8E4D1007E5}.Release|x86.ActiveCfg = Release|x86
{806258ED-F088-44A1-A6BE-2B8E4D1007E5}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal