Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/inc/apiv2/model/files.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ protected function createObject(array $data): int {
/* Since we are renaming the file _before_ import the name is temporary changed */
$dummyPost["imfile"] = [$data[File::FILENAME]];
break;
case "url":
$dummyPost["url"] = $data["sourceData"];
break;
default:
// TODO: Choice validation are model based checks
throw new HttpError("sourceType value '" . $data["sourceType"] . "' is not supported (choices inline, import");
throw new HttpError("sourceType value '" . $data["sourceType"] . "' is not supported (choices inline, import, url");
}

/* TODO: Hackish view to revert back to required (hardcoded) view */
Expand All @@ -144,7 +147,7 @@ protected function createObject(array $data): int {
}
catch (Exception $e) {
/* In case of errors, ensure old state is restored */
if (($data["sourceType"] == "import") && ($data[File::FILENAME] != $data["sourceData"])) {
if ($doRenameImport) {
rename(
$this->getImportPath() . $data[File::FILENAME],
$this->getImportPath() . $data["sourceData"]
Expand Down
6 changes: 4 additions & 2 deletions src/inc/utils/FileUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ public static function add($source, $file, $post, $view) {
break;
case "url":
// from url
$realname = str_replace(" ", "_", htmlentities(basename($post["url"]), ENT_QUOTES, "UTF-8"));
$realname = (isset($post["filename"])) ? $post["filename"] :
str_replace(" ", "_", htmlentities(basename($post["url"]), ENT_QUOTES, "UTF-8"));

if (strlen($realname) == 0) {
throw new HttpError("Empty URL provided!");
throw new HttpError("Empty URL/name provided!");
}
else if ($realname[0] == '.') {
$realname[0] = "_";
Expand Down