Skip to content

Commit d41a0c8

Browse files
author
jessevz
committed
Added url file upload for new API
1 parent 2d09508 commit d41a0c8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/inc/apiv2/model/files.routes.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ protected function createObject(array $data): int {
116116
/* Since we are renaming the file _before_ import the name is temporary changed */
117117
$dummyPost["imfile"] = [$data[File::FILENAME]];
118118
break;
119+
case "url":
120+
$dummyPost["url"] = $data["sourceData"];
121+
break;
119122
default:
120123
// TODO: Choice validation are model based checks
121-
throw new HttpError("sourceType value '" . $data["sourceType"] . "' is not supported (choices inline, import");
124+
throw new HttpError("sourceType value '" . $data["sourceType"] . "' is not supported (choices inline, import, url");
122125
}
123126

124127
/* TODO: Hackish view to revert back to required (hardcoded) view */
@@ -144,7 +147,7 @@ protected function createObject(array $data): int {
144147
}
145148
catch (Exception $e) {
146149
/* In case of errors, ensure old state is restored */
147-
if (($data["sourceType"] == "import") && ($data[File::FILENAME] != $data["sourceData"])) {
150+
if ($doRenameImport) {
148151
rename(
149152
$this->getImportPath() . $data[File::FILENAME],
150153
$this->getImportPath() . $data["sourceData"]

src/inc/utils/FileUtils.class.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,11 @@ public static function add($source, $file, $post, $view) {
206206
break;
207207
case "url":
208208
// from url
209-
$realname = str_replace(" ", "_", htmlentities(basename($post["url"]), ENT_QUOTES, "UTF-8"));
209+
$realname = (isset($post["filename"])) ? $post["filename"] :
210+
str_replace(" ", "_", htmlentities(basename($post["url"]), ENT_QUOTES, "UTF-8"));
211+
210212
if (strlen($realname) == 0) {
211-
throw new HttpError("Empty URL provided!");
213+
throw new HttpError("Empty URL/name provided!");
212214
}
213215
else if ($realname[0] == '.') {
214216
$realname[0] = "_";

0 commit comments

Comments
 (0)