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:
parent
4f4ae8f4df
commit
620cf2f892
4 changed files with 41 additions and 24 deletions
|
@ -21,12 +21,14 @@
|
||||||
|
|
||||||
<xsl:template match="ListingEntry[@Type='File']">
|
<xsl:template match="ListingEntry[@Type='File']">
|
||||||
<figure class='preview file'>
|
<figure class='preview file'>
|
||||||
<img src="{Name}?thumbnail" />
|
<img src="{Name}?type=thumbnail" />
|
||||||
|
<figcaption><xsl:value-of select="Name" /></figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
<xsl:template match="ListingEntry[@Type='Directory']">
|
<xsl:template match="ListingEntry[@Type='Directory']">
|
||||||
<figure class='preview directory'>
|
<figure class='preview directory'>
|
||||||
(coming soon)
|
(coming soon)
|
||||||
|
<figcaption><xsl:value-of select="Name" /></figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
</xsl:stylesheet>
|
</xsl:stylesheet>
|
||||||
|
|
|
@ -9,6 +9,8 @@ using System.Threading;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
using ImageMagick;
|
||||||
|
|
||||||
namespace GalleryShare
|
namespace GalleryShare
|
||||||
{
|
{
|
||||||
enum OutputFunction
|
enum OutputFunction
|
||||||
|
@ -21,8 +23,12 @@ namespace GalleryShare
|
||||||
|
|
||||||
class GalleryServer
|
class GalleryServer
|
||||||
{
|
{
|
||||||
|
static MimeSharp.Mime mimeDB = new MimeSharp.Mime();
|
||||||
|
|
||||||
int port;
|
int port;
|
||||||
string servingDirectory = Environment.CurrentDirectory;
|
string servingDirectory = Environment.CurrentDirectory;
|
||||||
|
int thumbnailWidth = 300;
|
||||||
|
int thumbnailHeight = 200;
|
||||||
|
|
||||||
HttpListener server = new HttpListener();
|
HttpListener server = new HttpListener();
|
||||||
string prefix;
|
string prefix;
|
||||||
|
@ -100,7 +106,7 @@ namespace GalleryShare
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OutputFunction.SendFile:
|
case OutputFunction.SendFile:
|
||||||
await sendFile(requestedPath);
|
await sendFile(cycle, requestedPath);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -216,9 +222,26 @@ namespace GalleryShare
|
||||||
await cycle.Response.OutputStream.WriteAsync(xsltData, 0, xsltData.Length);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
<RootNamespace>GalleryShare</RootNamespace>
|
<RootNamespace>GalleryShare</RootNamespace>
|
||||||
<AssemblyName>GalleryShare</AssemblyName>
|
<AssemblyName>GalleryShare</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
<ProductVersion>8.0.30703</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
@ -35,6 +33,13 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Xml" />
|
<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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
|
@ -43,10 +48,14 @@
|
||||||
<Compile Include="Utilities.cs" />
|
<Compile Include="Utilities.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<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>
|
<ItemGroup>
|
||||||
<Folder Include="Embed\**" />
|
<Folder Include="Embed\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Embed\**" />
|
<EmbeddedResource Include="Embed\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in a new issue