public static IEnumerator DoUpload(string username, string password, PackageVersion packageVersion, Action succeed) { var loginPage = UnityWebRequest.Get(LOGIN_URL); yield return(loginPage.Send()); if (loginPage.isError) { Debug.Log(loginPage.error); yield break; } // get the csrf cookie var SetCookie = loginPage.GetResponseHeader("set-cookie"); var rxCookie = new Regex("csrftoken=(?<csrf_token>.{64});"); var cookieMatches = rxCookie.Matches(SetCookie); var csrfCookie = cookieMatches[0].Groups["csrf_token"].Value; // get the middleware value // var loginPageHtml = loginPage.downloadHandler.text; // var rxMiddleware = new Regex("name='csrfmiddlewaretoken' value='(?<csrf_token>.{64})'"); // var middlewareMatches = rxMiddleware.Matches(loginPageHtml); // string csrfMiddlewareToken = middlewareMatches[0].Groups["csrf_token"].Value; /* * Make a login request. */ var form = new WWWForm(); var fileName = packageVersion.Name + "_" + packageVersion.Version + ".unitypackage"; var fullpath = FrameworkPMView.ExportPaths(fileName, packageVersion.InstallPath); var file = File.ReadAllBytes(fullpath); form.AddField("username", username); form.AddField("password", password); form.AddField("name", packageVersion.Name); form.AddField("file_name", fileName); form.AddBinaryData("file", file); form.AddField("version", packageVersion.Version); UnityWebRequest doLogin3 = UnityWebRequest.Post(UPLOAD_URL, form); doLogin3.SetRequestHeader("cookie", "csrftoken=" + csrfCookie); doLogin3.SetRequestHeader("X-CSRFToken", csrfCookie); File.Delete(fullpath); yield return(doLogin3.Send()); if (doLogin3.isError) { Log.E(doLogin3.error); } else { Log.I(doLogin3.downloadHandler.text); succeed.InvokeGracefully(); } }
public PublishPackageCommand(PackageVersion packageVersion) { mPackageVersion = packageVersion; }
public static IEnumerator DoUpload(string username, string password, PackageVersion packageVersion, Action succeed) { var loginPage = UnityWebRequest.Get(LOGIN_URL); EditorUtility.DisplayProgressBar("插件上传", "获取验证信息", 0.1f); yield return(loginPage.Send()); #if UNITY_2017_1_OR_NEWER if (loginPage.isNetworkError) #else if (loginPage.isError) #endif { Debug.Log(loginPage.error); yield break; } EditorUtility.DisplayProgressBar("插件上传", "生成 token", 0.1f); var SetCookie = loginPage.GetResponseHeader("set-cookie"); var rxCookie = new Regex("csrftoken=(?<csrf_token>.{64});"); var cookieMatches = rxCookie.Matches(SetCookie); var csrfCookie = cookieMatches[0].Groups["csrf_token"].Value; var form = new WWWForm(); var fileName = packageVersion.Name + "_" + packageVersion.Version + ".unitypackage"; var fullpath = FrameworkPMView.ExportPaths(fileName, packageVersion.InstallPath); var file = File.ReadAllBytes(fullpath); form.AddField("username", username); form.AddField("password", password); form.AddField("name", packageVersion.Name); form.AddField("file_name", fileName); form.AddBinaryData("file", file); form.AddField("version", packageVersion.Version); form.AddField("release_note", packageVersion.Readme.content); if (packageVersion.Type == PackageType.FrameworkModule) { form.AddField("type", "fm"); } else if (packageVersion.Type == PackageType.Shader) { form.AddField("type", "s"); } else if (packageVersion.Type == PackageType.AppOrGameDemoOrTemplate) { form.AddField("type", "agt"); } var doLogin3 = UnityWebRequest.Post(UPLOAD_URL, form); doLogin3.SetRequestHeader("cookie", "csrftoken=" + csrfCookie); doLogin3.SetRequestHeader("X-CSRFToken", csrfCookie); File.Delete(fullpath); yield return(doLogin3.Send()); EditorUtility.ClearProgressBar(); #if UNITY_2017_1_OR_NEWER if (doLogin3.isNetworkError) #else if (doLogin3.isError) #endif { EditorUtility.DisplayDialog("插件上传", "上传失败!{0}".FillFormat(doLogin3.error), "确定"); } else { Log.I(doLogin3.downloadHandler.text); succeed.InvokeGracefully(); } }