diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 53c7311..6eac4a6 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -286 \ No newline at end of file +292 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index 25bf17f..cabf43b 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -18 \ No newline at end of file +24 \ No newline at end of file diff --git a/Common/UploadManager.cs b/Common/UploadManager.cs index 72d1d26..4735792 100644 --- a/Common/UploadManager.cs +++ b/Common/UploadManager.cs @@ -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); } } diff --git a/Common/dataobjects/Upload.cs b/Common/dataobjects/Upload.cs index 9093fa5..fa857e5 100644 --- a/Common/dataobjects/Upload.cs +++ b/Common/dataobjects/Upload.cs @@ -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)) + ); + } + } } diff --git a/IISMainHandler/HandlersFactory.cs b/IISMainHandler/HandlersFactory.cs index 425da9e..96b5fa7 100644 --- a/IISMainHandler/HandlersFactory.cs +++ b/IISMainHandler/HandlersFactory.cs @@ -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": diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index fd9821b..800fb43 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -62,11 +62,14 @@ + + + diff --git a/IISMainHandler/handlers/StaticHandler.cs b/IISMainHandler/handlers/StaticHandler.cs index 04c4236..0668e8c 100644 --- a/IISMainHandler/handlers/StaticHandler.cs +++ b/IISMainHandler/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); } diff --git a/IISMainHandler/handlers/request/UploadHandler.cs b/IISMainHandler/handlers/request/UploadHandler.cs new file mode 100644 index 0000000..363025b --- /dev/null +++ b/IISMainHandler/handlers/request/UploadHandler.cs @@ -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) + }; + } + + } +} diff --git a/IISMainHandler/handlers/response/LegacyUploadHandler.cs b/IISMainHandler/handlers/response/LegacyUploadHandler.cs index 6d3a329..368189c 100644 --- a/IISMainHandler/handlers/response/LegacyUploadHandler.cs +++ b/IISMainHandler/handlers/response/LegacyUploadHandler.cs @@ -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 + "/"); } } diff --git a/IISMainHandler/handlers/response/UploadHandler.cs b/IISMainHandler/handlers/response/UploadHandler.cs index 4bea604..7edb6c3 100644 --- a/IISMainHandler/handlers/response/UploadHandler.cs +++ b/IISMainHandler/handlers/response/UploadHandler.cs @@ -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); } diff --git a/IISMainHandler/handlers/response/UploadListHandler.cs b/IISMainHandler/handlers/response/UploadListHandler.cs new file mode 100644 index 0000000..2876bdd --- /dev/null +++ b/IISMainHandler/handlers/response/UploadListHandler.cs @@ -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 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) + ) + }; + } + + } +} diff --git a/IISMainHandler/handlers/response/UploadNewHandler.cs b/IISMainHandler/handlers/response/UploadNewHandler.cs new file mode 100644 index 0000000..1b462e0 --- /dev/null +++ b/IISMainHandler/handlers/response/UploadNewHandler.cs @@ -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]; + } + + } +} diff --git a/IISUploadHandler/UploadHandler.cs b/IISUploadHandler/UploadHandler.cs index c76b4d4..e257284 100644 --- a/IISUploadHandler/UploadHandler.cs +++ b/IISUploadHandler/UploadHandler.cs @@ -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])); } diff --git a/ImportConsole/Program.cs b/ImportConsole/Program.cs index 34483ec..11746dd 100644 --- a/ImportConsole/Program.cs +++ b/ImportConsole/Program.cs @@ -105,7 +105,7 @@ namespace FLocal.ImportConsole { try { UploadManager.UploadFile( info.OpenRead(), - parts[1], + info.Name, info.LastWriteTime, uploader, id diff --git a/templates/Full/Login.xslt b/templates/Full/Login.xslt index dc7da04..bdfd4be 100644 --- a/templates/Full/Login.xslt +++ b/templates/Full/Login.xslt @@ -13,7 +13,8 @@ - Ââåäèòå âàøå èìÿ ïîëüçîâàòåëÿ è ïàðîëü äëÿ ðåãèñòðàöèè â ôîðóìå. + Ââåäèòå âàøå èìÿ ïîëüçîâàòåëÿ è ïàðîëü äëÿ ðåãèñòðàöèè â ôîðóìå. +
Åñëè âû åù¸ íå ïîëüçîâàëèñü ýòèì ôîðóìîì, íî ïðèøëè ñî ñòàðîãî ôîðóì.ëîêàëà – âû ìîæåòå ñîçäàòü ïàðîëü â ôîðìå ìèãðàöèè. diff --git a/templates/Full/UploadList.xslt b/templates/Full/UploadList.xslt new file mode 100644 index 0000000..f75e53f --- /dev/null +++ b/templates/Full/UploadList.xslt @@ -0,0 +1,45 @@ + + + + + + + + + +
+ + + + + + + + +
+ + + + +
+ ñòðàíèöû: + + /Upload/List/ + +
+
+ + + + +
+ ñòðàíèöû: + + /Upload/List/ + +
+
+
+
+ +
\ No newline at end of file diff --git a/templates/Full/UploadNew.xslt b/templates/Full/UploadNew.xslt new file mode 100644 index 0000000..bd2b232 --- /dev/null +++ b/templates/Full/UploadNew.xslt @@ -0,0 +1,34 @@ + + + + + + + + +
+ + + + + + + + + + +
+ Çàãðóçêà ôàéëîâ +
+ Âûáåðèòå ôàéë äëÿ çàãðóçêè + Ìàêñèìàëüíûé ðàçìåð ôàéëà – 1ÌÁ, äîïóñòèìûå ðàçðåøåíèÿ: gif, jpg, png +
+
+
+ +
+
+
+
+ +
\ No newline at end of file diff --git a/templates/Full/elems/Header.xslt b/templates/Full/elems/Header.xslt index ff5a7a6..6254cf9 100644 --- a/templates/Full/elems/Header.xslt +++ b/templates/Full/elems/Header.xslt @@ -38,6 +38,13 @@ | Ïîèñê | + + + /Upload/List/ + + Àïëîàä + + | My Home | diff --git a/templates/Full/elems/PostInfo.xslt b/templates/Full/elems/PostInfo.xslt index 146102e..a23be01 100644 --- a/templates/Full/elems/PostInfo.xslt +++ b/templates/Full/elems/PostInfo.xslt @@ -1,6 +1,7 @@ + @@ -8,54 +9,7 @@ Post - - - - - - - - - - - - - - - - - - - - - - - - - -
- - /User// - - -
- -
- -
- -
- -
- Ðåã.: - -
- Ñîîáùåíèé: - -
- Èç: - -
+ diff --git a/templates/Full/elems/UploadInfo.xslt b/templates/Full/elems/UploadInfo.xslt new file mode 100644 index 0000000..e220562 --- /dev/null +++ b/templates/Full/elems/UploadInfo.xslt @@ -0,0 +1,61 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/Full/elems/UserInfoBar.xslt b/templates/Full/elems/UserInfoBar.xslt new file mode 100644 index 0000000..31c5a85 --- /dev/null +++ b/templates/Full/elems/UserInfoBar.xslt @@ -0,0 +1,54 @@ + + + + +
+ + + + + + + + +
+ + + + /Upload/Item// + + + + + + [ + + ] + + +
+ +
+ + + + + + + + + +
+
+ + + /Upload/Item// + + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + /User// + + +
+ +
+ +
+ +
+ +
+ Ðåã.: + +
+ Ñîîáùåíèé: + +
+ Èç: + +
+ + \ No newline at end of file diff --git a/templates/Full/result/Upload.xslt b/templates/Full/result/Upload.xslt new file mode 100644 index 0000000..5018af4 --- /dev/null +++ b/templates/Full/result/Upload.xslt @@ -0,0 +1,33 @@ + + + + + + + + +
+ + + + + + + +
+ Çàãðóçêà ôàéëà +
+ Ôàéë óñïåøíî çàãðóæåí. +
+ Òåïåðü âû ìîæåòå âñòàâëÿòü ññûëêè íà íåãî ñ ïîìîùüþ òýãà [uploadLink= + + ] +
+ Äëÿ âñòàâêè êàðòèíêè âîñïîëüçóéòåñü òýãîì [uploadImage= + + ] +
+
+
+ +
\ No newline at end of file