Skip to content

Commit

Permalink
Limit length of file names
Browse files Browse the repository at this point in the history
Too long file names break the donwload process.
See https://forum.chitanka.info/topic6608.html

This is a quick fix, the whole download process should be refactored.

A related change: http://github.com/chitanka/chitanka/commit/049381f0b2d596a593add4c95893f4269b7c8e6b
  • Loading branch information
bmanolov committed Sep 26, 2021
1 parent feee398 commit e29b518
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/Entity/Text.php
Expand Up @@ -871,13 +871,22 @@ public function getDataAsPlain() {
}

public function getNameForFile() {
return strtr(Setup::setting('download_file'), [
$lengthLimits = [
'AUTHOR' => 50,
'SERIES' => 50,
'TITLE' => 100,
];
$parts = [
'AUTHOR' => $this->getAuthorNameEscaped(),
'SERIES' => empty($this->series) ? '' : Stringy::createAcronym(Char::cyr2lat($this->series->getName())),
'SERNO' => $this->getSernr() ?? '',
'TITLE' => Char::cyr2lat($this->title),
'ID' => $this->getId(),
]);
];
array_walk($parts, function(string &$value, string $name) use ($lengthLimits) {
$value = substr($value, 0, $lengthLimits[$name] ?? 20);
});
return strtr(Setup::setting('download_file'), $parts);
}

public static function getMinRating() {
Expand Down
1 change: 1 addition & 0 deletions app/Generator/TextDownloadService.php
Expand Up @@ -191,6 +191,7 @@ private function createDlFile($textIds, $format, $dlkey = null) {
$this->zipFileName = "Архив от Моята библиотека - $fileCount файла-".time();
}

$this->zipFileName = substr($this->zipFileName, 0, 230);
$this->zipFileName .= $fileCount > 1 ? "-$format" : $dlkey;
$this->zipFileName = File::cleanFileName( Char::cyr2lat($this->zipFileName) );
$fullZipFileName = $this->zipFileName . '.zip';
Expand Down

0 comments on commit e29b518

Please sign in to comment.