예제 #1
0
        private static void Upload(Store <AppState> store)
        {
            var token = UnityConnectSession.instance.GetAccessToken();

            if (token.Length == 0)
            {
                CheckLoginStatus(store);
                return;
            }

            var path         = store.state.shareState.zipPath;
            var title        = store.state.shareState.title;
            var baseUrl      = getAPIBaseUrl();
            var projectId    = GetProjectId();
            var formSections = new List <IMultipartFormSection>();

            formSections.Add(new MultipartFormDataSection("title", title));

            if (projectId.Length > 0)
            {
                formSections.Add(new MultipartFormDataSection("projectId", projectId));
            }

            formSections.Add(new MultipartFormFileSection("file",
                                                          File.ReadAllBytes(path), Path.GetFileName(path), "application/zip"));

            uploadRequest = UnityWebRequest.Post(baseUrl + uploadEndpoint, formSections);
            uploadRequest.SetRequestHeader("Authorization", $"Bearer {token}");
            uploadRequest.SetRequestHeader("X-Requested-With", "XMLHTTPREQUEST");

            var op = uploadRequest.SendWebRequest();

            ConnectShareEditorWindow.StartCoroutine(updateProgress(store, uploadRequest));

            op.completed += operation =>
            {
                if (uploadRequest.isNetworkError || uploadRequest.isHttpError)
                {
                    Debug.Log(uploadRequest.error);
                    if (uploadRequest.error != "Request aborted")
                    {
                        store.Dispatch(new OnErrorAction {
                            errorMsg = "Internal server error"
                        });
                    }
                }
                else
                {
                    var response = JsonUtility.FromJson <UploadResponse>(op.webRequest.downloadHandler.text);
                    if (!string.IsNullOrEmpty(response.key))
                    {
                        store.Dispatch(new QueryProgressAction {
                            key = response.key
                        });
                    }
                }
            };
        }
예제 #2
0
        private static void CheckLoginStatus(Store <AppState> store)
        {
            var token = UnityConnectSession.instance.GetAccessToken();

            if (token.Length == 0)
            {
                ConnectShareEditorWindow.StartCoroutine(wait(2f)).promise.Then((obj) =>
                {
                    store.Dispatch(new NotLoginAction());
                });
            }
            else
            {
                store.Dispatch(new LoginAction());
            }
        }
예제 #3
0
        private static void CheckProgress(Store <AppState> store, string key)
        {
            var token = UnityConnectSession.instance.GetAccessToken();

            if (token.Length == 0)
            {
                CheckLoginStatus(store);
                return;
            }

            key = key ?? store.state.shareState.key;
            var baseUrl       = getAPIBaseUrl();
            var uploadRequest = UnityWebRequest.Get($"{baseUrl + queryProgressEndpoint}?key={key}");

            uploadRequest.SetRequestHeader("Authorization", $"Bearer {token}");
            uploadRequest.SetRequestHeader("X-Requested-With", "XMLHTTPREQUEST");
            var op = uploadRequest.SendWebRequest();

            op.completed += operation =>
            {
                if (uploadRequest.isNetworkError || uploadRequest.isHttpError)
                {
                    Debug.Log(uploadRequest.error);
                }
                else
                {
                    var response = JsonUtility.FromJson <GetProgressResponse>(op.webRequest.downloadHandler.text);

                    store.Dispatch(new QueryProgressResponseAction {
                        response = response
                    });
                    if (response.progress == 100 || !string.IsNullOrEmpty(response.error))
                    {
                        SaveProjectID(response.projectId);
                        return;
                    }
                }

                ConnectShareEditorWindow.StartCoroutine(wait(1.5f)).promise.Then((obj) =>
                {
                    store.Dispatch(new QueryProgressAction());
                });
            };
        }