using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using EKETEAM.Data;
using EKETEAM.FrameWork;
using LitJson;


namespace eFrameWork.Plugins2
{
    public partial class ProUpload : System.Web.UI.Page
    {
        public eExtensionsList allowExts = new eExtensionsList();
        protected void Page_Load(object sender, EventArgs e)
        {
            string act = eParameters.QueryString("action");
            if (act == "config")
            {
                //ConfigHandler action = new ConfigHandler(this.Context);
                //action.Process();
                //return;
                string json = eBase.ReadFile(Server.MapPath("config.json"));
                eBase.WriteJson(json);
            }
            //uploadimage {"state":"SUCCESS","url":"upload/20230327/6381555147921945915324171.png","title":"logo.png","original":"logo.png","error":null}
            //uploadvideo {"state":"SUCCESS","url":"upload/20230327/6381555178903717973218094.mp4","title":"201810301537484450.mp4","original":"201810301537484450.mp4","error":null}
            //uploadfile  {"state":"SUCCESS","url":"upload/20230327/6381555188769182242042436.doc","title":"白皮书.doc","original":"白皮书.doc","error":null}
            if (Request.Files.Count > 0)
            {
                HttpPostedFile file = Request.Files[0];
                eFileResult result = file.safeSave(eRunTime.tempPath);
                JsonData jd = new JsonData();
                if (result.Success)
                {
                    jd["state"] = "SUCCESS";
                    jd["url"] =eRunTime.baseUrl +  eRunTime.tempPath.toVirtualUrl() + result.Content;
                    jd["title"] = file.FileName;
                    jd["original"] = file.FileName;
                    jd["error"] = null;
                }
                else
                {
                    jd["state"] = "未知错误";
                    jd["error"] = "未知错误";
                }
                eResult.WriteJson(jd);

            }
        }
    }
}