Upload list implemented; uploads implemented; bugfixes

main
Inga 🏳‍🌈 14 years ago
parent dca8ed5ff8
commit 20c5fb0be2
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      Builder/IISUploadHandler/build.txt
  3. 11
      Common/UploadManager.cs
  4. 21
      Common/dataobjects/Upload.cs
  5. 16
      IISMainHandler/HandlersFactory.cs
  6. 3
      IISMainHandler/IISMainHandler.csproj
  7. 5
      IISMainHandler/handlers/StaticHandler.cs
  8. 33
      IISMainHandler/handlers/request/UploadHandler.cs
  9. 2
      IISMainHandler/handlers/response/LegacyUploadHandler.cs
  10. 5
      IISMainHandler/handlers/response/UploadHandler.cs
  11. 44
      IISMainHandler/handlers/response/UploadListHandler.cs
  12. 26
      IISMainHandler/handlers/response/UploadNewHandler.cs
  13. 4
      IISUploadHandler/UploadHandler.cs
  14. 2
      ImportConsole/Program.cs
  15. 3
      templates/Full/Login.xslt
  16. 45
      templates/Full/UploadList.xslt
  17. 34
      templates/Full/UploadNew.xslt
  18. 7
      templates/Full/elems/Header.xslt
  19. 50
      templates/Full/elems/PostInfo.xslt
  20. 61
      templates/Full/elems/UploadInfo.xslt
  21. 54
      templates/Full/elems/UserInfoBar.xslt
  22. 33
      templates/Full/result/Upload.xslt

@ -37,9 +37,9 @@ namespace FLocal.Common {
"png",
};
public static void UploadFile(Stream fileStream, string _extension, DateTime uploadDate, User uploader, int? id) {
public static Upload UploadFile(Stream fileStream, string filename, DateTime uploadDate, User uploader, int? id) {
string extension = _extension.ToLower();
string extension = filename.Split('.').Last().ToLower();
if(!allowedExtensions.Contains(extension)) throw new FLocalException("Unsupported extension");
if(fileStream.Length > MAX_UPLOAD_FILESIZE) throw new FLocalException("File is too big");
@ -55,6 +55,9 @@ namespace FLocal.Common {
ComparisonType.EQUAL,
file_md5
);
int? uploadId = null;
try {
if(Config.instance.mainConnection.GetCountByConditions(Upload.TableSpec.instance, condition, new JoinSpec[0]) > 0) {
throw new _AlreadyUploadedException();
@ -93,7 +96,8 @@ namespace FLocal.Common {
row[Upload.TableSpec.FIELD_UPLOADDATE] = uploadDate.ToUTCString();
row[Upload.TableSpec.FIELD_USERID] = uploader.id.ToString();
row[Upload.TableSpec.FIELD_SIZE] = data.Length.ToString();
Config.instance.mainConnection.insert(transaction, Upload.TableSpec.instance, row);
row[Upload.TableSpec.FIELD_FILENAME] = filename;
uploadId = int.Parse(Config.instance.mainConnection.insert(transaction, Upload.TableSpec.instance, row));
});
} catch(_AlreadyUploadedException) {
throw new AlreadyUploadedException(
@ -107,6 +111,7 @@ namespace FLocal.Common {
)
);
}
return Upload.LoadById(uploadId.Value);
}
}

@ -16,6 +16,7 @@ namespace FLocal.Common.dataobjects {
public const string FIELD_HASH = "MD5";
public const string FIELD_EXTENSION = "Extension";
public const string FIELD_SIZE = "Size";
public const string FIELD_FILENAME = "Filename";
public const string FIELD_UPLOADDATE = "UploadDate";
public const string FIELD_USERID = "UserId";
public static readonly TableSpec instance = new TableSpec();
@ -50,6 +51,14 @@ namespace FLocal.Common.dataobjects {
}
}
private string _filename;
public string filename {
get {
this.LoadIfNotLoaded();
return this._filename;
}
}
private DateTime _uploadDate;
public DateTime uploadDate {
get {
@ -75,9 +84,21 @@ namespace FLocal.Common.dataobjects {
this._hash = data[TableSpec.FIELD_HASH];
this._extension = data[TableSpec.FIELD_EXTENSION];
this._size = int.Parse(data[TableSpec.FIELD_SIZE]);
this._filename = data[TableSpec.FIELD_FILENAME];
this._uploadDate = Util.ParseDateTimeFromTimestamp(data[TableSpec.FIELD_UPLOADDATE]).Value;
this._userId = Util.ParseInt(data[TableSpec.FIELD_USERID]);
}
public XElement exportToXml(UserContext context) {
return new XElement("upload",
new XElement("id", this.id),
new XElement("extension", this.extension),
new XElement("size", this.size),
new XElement("filename", this.filename),
new XElement("uploadDate", this.uploadDate.ToXml()),
new XElement("uploader", this.user.exportToXmlForViewing(context))
);
}
}
}

@ -40,8 +40,20 @@ namespace FLocal.IISHandler {
return new handlers.response.UserListHandler();
case "user":
return new handlers.response.UserInfoHandler();
case "uploads":
return new handlers.response.UploadHandler();
case "upload":
if(context.requestParts.Length < 2) {
return new handlers.WrongUrlHandler();
}
switch(context.requestParts[1].ToLower()) {
case "item":
return new handlers.response.UploadHandler();
case "new":
return new handlers.response.UploadNewHandler();
case "list":
return new handlers.response.UploadListHandler();
default:
return new handlers.WrongUrlHandler();
}
case "static":
return new handlers.StaticHandler(context.requestParts);
case "do":

@ -62,11 +62,14 @@
<Compile Include="handlers\request\LoginHandler.cs" />
<Compile Include="handlers\request\LogoutHandler.cs" />
<Compile Include="handlers\request\MigrateAccountHandler.cs" />
<Compile Include="handlers\request\UploadHandler.cs" />
<Compile Include="handlers\response\BoardAsThread.cs" />
<Compile Include="handlers\response\LegacyUploadHandler.cs" />
<Compile Include="handlers\response\LoginHandler.cs" />
<Compile Include="handlers\response\MigrateAccountHandler.cs" />
<Compile Include="handlers\response\UploadHandler.cs" />
<Compile Include="handlers\response\UploadListHandler.cs" />
<Compile Include="handlers\response\UploadNewHandler.cs" />
<Compile Include="handlers\response\UserInfoHandler.cs" />
<Compile Include="handlers\RootHandler.cs" />
<Compile Include="handlers\StaticHandler.cs" />

@ -46,8 +46,9 @@ namespace FLocal.IISHandler.handlers {
throw new HttpException(403, "wrong file type");
}
context.httpresponse.CacheControl = HttpCacheability.Public.ToString();
context.httpresponse.Expires = 1440;
context.httpresponse.Cache.SetExpires(DateTime.Now.AddDays(10));
context.httpresponse.Cache.SetLastModified(fileinfo.LastWriteTime);
context.httpresponse.Cache.SetCacheability(HttpCacheability.Public);
context.httpresponse.TransmitFile(fileinfo.FullName);
}

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using FLocal.Common.dataobjects;
using FLocal.Importer;
using System.Text.RegularExpressions;
using FLocal.Core;
using FLocal.Common;
using FLocal.Common.actions;
using System.Web;
namespace FLocal.IISHandler.handlers.request {
class UploadHandler : AbstractPostHandler {
protected override string templateName {
get {
return "result/Upload.xslt";
}
}
protected override XElement[] Do(WebContext context) {
HttpPostedFile file = context.httprequest.Files["uploaded"];
if(file == null) throw new FLocalException("file not uploaded");
Upload upload = UploadManager.UploadFile(file.InputStream, System.IO.Path.GetFileName(file.FileName), DateTime.Now, context.session.account.user, null);
return new XElement[] {
new XElement("uploadedId", upload.id)
};
}
}
}

@ -36,7 +36,7 @@ namespace FLocal.IISHandler.handlers.response {
default:
throw new FLocalException("wrong url");
}
throw new RedirectException("/Uploads/" + fileNum + "/");
throw new RedirectException("/Upload/Item/" + fileNum + "/");
}
}

@ -6,6 +6,8 @@ using FLocal.Core;
using FLocal.Common;
using System.Xml.Linq;
using FLocal.Common.dataobjects;
using FLocal.Core.DB;
using FLocal.Core.DB.conditions;
namespace FLocal.IISHandler.handlers.response {
class UploadHandler : AbstractGetHandler {
@ -17,8 +19,7 @@ namespace FLocal.IISHandler.handlers.response {
}
protected override System.Xml.Linq.XElement[] getSpecificData(WebContext context) {
if(context.requestParts.Length != 2) throw new FLocalException("wrong url");
Upload upload = Upload.LoadById(int.Parse(context.requestParts[1]));
Upload upload = Upload.LoadById(int.Parse(context.requestParts[2]));
throw new RedirectException(Config.instance.UploaderUrl + "Data/" + upload.hash + "." + upload.extension);
}

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Core;
using FLocal.Common;
using System.Xml.Linq;
using FLocal.Common.dataobjects;
using FLocal.Core.DB;
using FLocal.Core.DB.conditions;
namespace FLocal.IISHandler.handlers.response {
class UploadListHandler : AbstractGetHandler {
protected override string templateName {
get {
return "UploadList.xslt";
}
}
protected override System.Xml.Linq.XElement[] getSpecificData(WebContext context) {
if(context.session == null) throw new AccessViolationException();
PageOuter pageOuter = PageOuter.createFromGet(context.requestParts, 100, 2);
List<Upload> uploads = Upload.LoadByIds(
from stringId in Config.instance.mainConnection.LoadIdsByConditions(
Upload.TableSpec.instance,
new MultiValueCondition(
Upload.TableSpec.instance.getColumnSpec(Upload.TableSpec.FIELD_EXTENSION),
new string[] { "jpg", "gif", "png" }
),
pageOuter,
new JoinSpec[0]
) select int.Parse(stringId)
);
return new XElement[] {
new XElement("uploads",
from upload in uploads select upload.exportToXml(context),
pageOuter.exportToXml(2, 5, 2)
)
};
}
}
}

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLocal.Core;
using FLocal.Common;
using System.Xml.Linq;
using FLocal.Common.dataobjects;
using FLocal.Core.DB;
using FLocal.Core.DB.conditions;
namespace FLocal.IISHandler.handlers.response {
class UploadNewHandler : AbstractGetHandler {
protected override string templateName {
get {
return "UploadNew.xslt";
}
}
protected override System.Xml.Linq.XElement[] getSpecificData(WebContext context) {
return new XElement[0];
}
}
}

@ -72,6 +72,10 @@ namespace FLocal.IISUploadHandler {
if(mime == null) throw new FLocalException("unknown extension '" + fileParts[1] + "'");
context.Response.ContentType = mime;
context.Response.Cache.SetExpires(DateTime.Now.AddDays(10));
context.Response.Cache.SetLastModified(DateTime.Now.AddYears(-1));
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.TransmitFile(getFilePath(fileParts[0], fileParts[1]));
}

@ -105,7 +105,7 @@ namespace FLocal.ImportConsole {
try {
UploadManager.UploadFile(
info.OpenRead(),
parts[1],
info.Name,
info.LastWriteTime,
uploader,
id

@ -13,7 +13,8 @@
</tr>
<tr class="darktable">
<td>
<xsl:text>Введите ваше имя пользователя и пароль для регистрации в форуме. </xsl:text>
<xsl:text>Введите ваше имя пользователя и пароль для регистрации в форуме.</xsl:text>
<br/>
<xsl:text>Если вы ещё не пользовались этим форумом, но пришли со старого форум.локала &#150; вы можете создать пароль в форме миграции.</xsl:text>
</td>
</tr>

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="elems\Main.xslt"/>
<xsl:import href="elems\UploadInfo.xslt"/>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="0" cellspacing="1" width="100%" class="tableborders">
<tr class="tdheader">
<td>
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr>
<td>
<xsl:text>ñòðàíèöû:</xsl:text>
<xsl:apply-templates select="uploads/pageOuter" mode="withCurrent">
<xsl:with-param name="baseLink">/Upload/List/</xsl:with-param>
</xsl:apply-templates>
</td>
</tr>
</table>
</td>
</tr>
<xsl:apply-templates select="uploads/upload"/>
<tr class="tdheader">
<td>
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr>
<td>
<xsl:text>ñòðàíèöû:</xsl:text>
<xsl:apply-templates select="uploads/pageOuter" mode="withCurrent">
<xsl:with-param name="baseLink">/Upload/List/</xsl:with-param>
</xsl:apply-templates>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="elems\Main.xslt"/>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Çàãðóçêà ôàéëîâ</xsl:text>
</td>
</tr>
<tr class="darktable">
<td>
<xsl:text>Âûáåðèòå ôàéë äëÿ çàãðóçêè</xsl:text>
<xsl:text>Ìàêñèìàëüíûé ðàçìåð ôàéëà &#150; 1ÌÁ, äîïóñòèìûå ðàçðåøåíèÿ: gif, jpg, png</xsl:text>
</td>
</tr>
<tr>
<td class="lighttable">
<form method="post" action="/do/Upload/">
<input type="file" name="uploaded" class="formboxes" /><br/>
<input type="submit" name="buttlogin" value="Îòïðàâèòü!" class="buttons" />
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>

@ -38,6 +38,13 @@
<xsl:text> | </xsl:text>
<a target="_top">Ďîčńę</a>
<xsl:text> | </xsl:text>
<a target="_top">
<xsl:if test="session/sessionKey">
<xsl:attribute name="href">/Upload/List/</xsl:attribute>
</xsl:if>
<xsl:text>Àïëîàä</xsl:text>
</a>
<xsl:text> | </xsl:text>
<a target="_top">My Home</a>
<xsl:text> | </xsl:text>
<a target="_top">

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="UserInfoBar.xslt"/>
<xsl:template match="post">
<tr>
<td>
@ -8,54 +9,7 @@
<tr>
<td width="120" valign="top" class="darktable" rowspan="2">
<a><xsl:attribute name="name">Post<xsl:value-of select="id"/></xsl:attribute></a>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a>
<xsl:attribute name="href">/User/<xsl:value-of select="poster/user/id"/>/</xsl:attribute>
<xsl:value-of select="poster/user/name"/>
</a>
</td>
</tr>
<tr>
<td class="small">
<b><xsl:value-of select="poster/user/title"/></b>
</td>
</tr>
<tr>
<td class="small">
<i></i>
</td>
</tr>
<tr>
<td class="small">
<i><font color="red"></font></i>
</td>
</tr>
<tr>
<td class="small">
<img src="/user/7901.jpg" alt="" width="80" height="80" />
</td>
</tr>
<tr>
<td class="small">
<xsl:text>Ðåã.: </xsl:text>
<xsl:apply-templates select="poster/user/regDate/date" mode="date"/>
</td>
</tr>
<tr>
<td class="small">
<xsl:text>Ñîîáùåíèé: </xsl:text>
<xsl:value-of select="poster/user/totalPosts"/>
</td>
</tr>
<tr>
<td class="small">
<xsl:text>Èç: </xsl:text>
<xsl:value-of select="poster/user/location"/>
</td>
</tr>
</table>
<xsl:apply-templates select="poster/user" mode="userInfoBar"/>
</td>
<td class="subjecttable">
<table width="100%" border="0" cellpadding="0" cellspacing="0">

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="UserInfoBar.xslt"/>
<xsl:template match="upload">
<tr>
<td>
<table width="100%" cellspacing="1" cellpadding="3" border="0">
<tr>
<td width="120" valign="top" class="darktable" rowspan="2">
<xsl:apply-templates select="uploader/user" mode="userInfoBar"/>
</td>
<td class="subjecttable">
<a target="_blank" class="separate">
<xsl:attribute name="href">/Upload/Item/<xsl:value-of select="id"/>/</xsl:attribute>
<img border="0" src="/static/images/book-read.gif" alt="" style="vertical-align: text-bottom" />
</a>
<b class="separate"><xsl:value-of select="filename"/></b>
<xsl:if test="parentPost/post">
<font class="small separate">
<xsl:text>[</xsl:text>
<xsl:value-of select="size"/>
<xsl:text>]</xsl:text>
</font>
</xsl:if>
<br />
<font class="small" style="padding-left:2em"><xsl:apply-templates select="uploadDate/date" mode="dateTime"/></font>
</td>
</tr>
<tr>
<td class="lighttable">
<table width="100%" cellspacing="0" cellpadding="0" style="table-layout: fixed">
<tr>
<td>
<br />
<font class="post">
<img style="max-width:800px;max-height:600px;">
<xsl:attribute name="src">/Upload/Item/<xsl:value-of select="id"/>/</xsl:attribute>
</img>
</font>
</td>
</tr>
<xsl:if test="uploader/user/signature != ''">
<tr>
<td>
<div style="width:100%;max-height:50px;height: expression( this.scrollHeight > 49 ? '50px' : 'auto' );overflow:hidden">
<font size="-2"><xsl:value-of select="poster/user/signature"/><br /></font>
</div>
</td>
</tr>
</xsl:if>
</table>
</td>
</tr>
</table>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="user" mode="userInfoBar">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a>
<xsl:attribute name="href">/User/<xsl:value-of select="id"/>/</xsl:attribute>
<xsl:value-of select="name"/>
</a>
</td>
</tr>
<tr>
<td class="small">
<b><xsl:value-of select="title"/></b>
</td>
</tr>
<tr>
<td class="small">
<i></i>
</td>
</tr>
<tr>
<td class="small">
<i><font color="red"></font></i>
</td>
</tr>
<tr>
<td class="small">
<img src="/user/7901.jpg" alt="" width="80" height="80" />
</td>
</tr>
<tr>
<td class="small">
<xsl:text>Ðåã.: </xsl:text>
<xsl:apply-templates select="regDate/date" mode="date"/>
</td>
</tr>
<tr>
<td class="small">
<xsl:text>Ñîîáùåíèé: </xsl:text>
<xsl:value-of select="totalPosts"/>
</td>
</tr>
<tr>
<td class="small">
<xsl:text>Èç: </xsl:text>
<xsl:value-of select="location"/>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="..\elems\Main.xslt"/>
<xsl:template name="specific">
<table width="95%" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="3" cellspacing="1" width="100%" class="tableborders">
<tr>
<td class="tdheader">
<xsl:text>Çàãðóçêà ôàéëà</xsl:text>
</td>
</tr>
<tr>
<td class="lighttable">
<xsl:text>Ôàéë óñïåøíî çàãðóæåí.</xsl:text>
<br/>
<xsl:text>Òåïåðü âû ìîæåòå âñòàâëÿòü ññûëêè íà íåãî ñ ïîìîùüþ òýãà [uploadLink=</xsl:text>
<xsl:value-of select="uploadedId"/>
<xsl:text>]</xsl:text>
<br/>
<xsl:text>Äëÿ âñòàâêè êàðòèíêè âîñïîëüçóéòåñü òýãîì [uploadImage=</xsl:text>
<xsl:value-of select="uploadedId"/>
<xsl:text>]</xsl:text>
</td>
</tr>
</table>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>
Loading…
Cancel
Save