Example #1
0
        public ArchivedDirectory(ArchiveSite site, DirectoryInfo dir) : base(site)
        {
            subDirs   = new List <ArchivedDirectory>();
            subFiles  = new List <ArchivedFile>();
            this.info = dir;

            //Load the metadata if it has some. If it doesn't create it
            if (File.Exists(dir.FullName + "/INFO.dirmeta"))
            {
                metadata = JsonConvert.DeserializeObject <ArchivedDirectoryMetadata>(File.ReadAllText(dir.FullName + "/INFO.dirmeta"));
            }
            else
            {
                throw new Exception("No info found for dir!");
            }
            uploadedDate = new FileInfo(dir.FullName + "/INFO.dirmeta").LastWriteTimeUtc;

            //Load the custom footer, if any
            if (File.Exists(dir.FullName + "/FOOTER.dirmeta"))
            {
                footer = File.ReadAllText(dir.FullName + "/FOOTER.dirmeta");
            }
            else
            {
                footer = "";
            }

            //Set rich metadata
            rich_metadata_status = MetadataStatus.NO_METADATA;
        }
Example #2
0
        public async Task OnAdminEditDir(HttpContext e)
        {
            //Check if we need to show the form
            if (e.Request.Method.ToUpper() != "POST")
            {
                //Set headers
                e.Response.ContentType = "text/html";

                //Show form
                await TemplateManager.WriteTemplate(e.Response.Body, "ADMIN.EDIT_DIR", new Dictionary <string, string>
                {
                    { "PATH", path },
                    { "DIR_TITLE", metadata.title },
                    { "DIR_DESCRIPTION", HttpUtility.HtmlEncode(metadata.description) },
                    { "DIR_FOOTER", HttpUtility.HtmlEncode(footer) },
                });
            }
            else
            {
                //Run
                var form = await e.Request.ReadFormAsync();

                //Read data
                string title       = form["dir_title"];
                string description = form["dir_description"];
                string newFooter   = form["footer"];

                //Create metadata
                var metadata = new ArchivedDirectoryMetadata
                {
                    title       = title,
                    description = description
                };
                File.WriteAllText(info.FullName + "/INFO.dirmeta", JsonConvert.SerializeObject(metadata));

                //Create footer (if any)
                if (newFooter.Length > 0)
                {
                    File.WriteAllText(info.FullName + "/FOOTER.dirmeta", newFooter);
                }
                else if (File.Exists(info.FullName + "/FOOTER.dirmeta"))
                {
                    File.Delete(info.FullName + "/FOOTER.dirmeta");
                }

                //Update
                metadata.title       = title;
                metadata.description = description;
                footer = newFooter;

                //Redirect to this
                e.Response.Redirect(site.config.client_pathname_prefix + path_urlsafe, false);
            }
        }
Example #3
0
        public async Task OnAdminCreateDir(HttpContext e)
        {
            //Check if we need to show the form
            if (e.Request.Method.ToUpper() != "POST")
            {
                //Set headers
                e.Response.ContentType = "text/html";

                //Show form
                await TemplateManager.WriteTemplate(e.Response.Body, "ADMIN.CREATE_DIR", new Dictionary <string, string>
                {
                    { "PATH", path }
                });
            }
            else
            {
                //Run
                var form = await e.Request.ReadFormAsync();

                //Read data
                string name        = form["dir_name"];
                string title       = form["dir_title"];
                string description = form["dir_description"];
                string footer      = form["footer"];

                //Get the pathname
                string pathname = info.FullName + "/" + name + "/";

                //Check
                if (Directory.Exists(pathname))
                {
                    e.Response.ContentType = "text/html";
                    await e.WriteString("<span style=\"color: red;\">The directory you're attempting to create already exists. Aborting!</span>");

                    return;
                }

                //Create directory
                Directory.CreateDirectory(pathname);

                //Create metadata
                var metadata = new ArchivedDirectoryMetadata
                {
                    title       = title,
                    description = description
                };
                File.WriteAllText(pathname + "INFO.dirmeta", JsonConvert.SerializeObject(metadata));

                //Create footer (if any)
                if (footer.Length > 0)
                {
                    File.WriteAllText(pathname + "FOOTER.dirmeta", footer);
                }

                //Refresh
                site.RefreshObjects();

                //Redirect to this
                e.Response.Redirect(site.config.client_pathname_prefix + path_urlsafe, false);
            }
        }