Пример #1
0
        public void libraryUpload(string[] uploadFilePath, string[] contentId)
        {
            if (uploadFilePath != null)
            {
                H5PCore.ajaxError(this.core.t("Could not get posted H5P."), "NO_CONTENT_TYPE", 0);
                return;
            }

            var file = this.saveFileTemporarily(uploadFilePath, true);

            if (!file)
            {
                return;
            }

            if (!this.isValidPackage())
            {
                return;
            }

            var storage = new H5PStorage(h5pF, core);

            storage.savePackage(null, null, true);

            var content = this.core.moveContentDirectory(this.getUploadedH5pFolderPath(), contentId);

            this.storage.removeTemporarilySavedFiles(this.core.getUploadedH5pFolderPath());

            Dictionary <string, dynamic> ht = new Dictionary <string, dynamic>();

            ht.Add("h5p", content.h5pJson());
            ht.Add("content", content.contentJson());
            ht.Add("contentTypes", this.getContentTypeCache());
            H5PCore.ajaxSuccess(ht);
        }
Пример #2
0
 public void libraryInstall(string[] machineName)
 {
     if (machineName != null)
     {
         H5PCore.ajaxError(this.core.t("No content type was specified."), "NO_CONTENT_TYPE", 0);
         return;
     }
 }
Пример #3
0
 public bool isHubOn()
 {
     if (!this.core.getOption("hub_is_enabled", true))
     {
         H5PCore.ajaxError(this.core.t("The hub is disabled. You can enable it in the H5P settings"), "HUB_DISABLED", 403);
         return(false);
     }
     return(true);
 }
Пример #4
0
        public bool isValidEditorToken(string[] token)
        {
            isValidToken = this.editor.validateEditorToken(token[0]);

            if (!isValidToken)
            {
                H5PCore.ajaxError(this.core.t("Invalid security token"), "INVALID_TOKEN", 0);
                return(false);
            }
            return(true);
        }
Пример #5
0
        public bool saveFileTemporarily(string[] data, bool move_file = false)
        {
            var file = this.storage.saveFileTemporarily(data, move_file);

            if (!file)
            {
                H5PCore.ajaxError(this.core.t("Failed to download the requested H5P."), "DOWNLOAD_FAILED", 0);
                return(false);
            }
            return(file);
        }
Пример #6
0
        public bool callHubEndpoint(string endpoint)
        {
            var path     = this.core.getUploadedH5pPath();
            var response = this.core.fetchExternalData(H5PHubEndpoints.createURL(endpoint), null, true, string.IsNullOrEmpty(path) ? null : path);

            if (!response)
            {
                H5PCore.ajaxError(this.core.t("Failed to download the requested H5P"), "DOWNLOAD_FAILED", null, this.core.getMessages("error"));
                return(false);
            }
            return(true);
        }
Пример #7
0
        public bool isPostRequest()
        {
            var _SERVER = new Dictionary <string, dynamic>();

            _SERVER.Add("REQUEST_METHOD", "POST");
            if (_SERVER["REQUEST_METHOD"] != "POST")
            {
                H5PCore.ajaxError(this.core.t("A post message is required to access the given endpoint"), "REQUIRES_POST", 405);
                return(false);
            }
            return(true);
        }
Пример #8
0
        public bool isValidPackage(bool skipContent = false)
        {
            var validator = new H5PValidator(this.h5pF, this.core);

            if (!validator.isValidPackage(skipContent, false))
            {
                this.storage.removeTemporarilySavedFiles(this.core.getUploadedH5pPath());

                H5PCore.ajaxError(this.core.t("Validating h5p package failed."), "VALIDATION_FAILED", null, this.core.getMessages("Error"));
                return(false);
            }
            return(true);
        }
Пример #9
0
        public void fileUpload(int contentId = 0)
        {
            file = new H5peditorFile(this.core.h5pF);
            if (!file.isLoaded())
            {
                H5PCore.ajaxError(this.core.t("File not found on server. Check file upload settings."));
                return;
            }

            if (file.validate())
            {
                var file_id = this.core.saveFile(file, 0);
                this.storage.markFileForCleanup(file_id);
            }

            file.printResult();
        }