Scripler / scripler

The Scripler web application source code repository
Do What The F*ck You Want To Public License
5 stars 1 forks source link

Epubs are not named after project title anymore (staging) #771

Closed Abekonge closed 9 years ago

Abekonge commented 9 years ago

... they get the project id.

mortengf commented 9 years ago

@allanmc This is turning out to be more complicated than I anticipated. As I see it we need three EPUB files in play:

  1. The file saved in the user's folder named after the project id.
  2. The temporary file validated by the EPUB validator (separate file due to #483)
  3. A file named after the metadata title / project's name (what this issue is about).

In our current solution we only have the first and second and I am trying to introduce the third file but I am running into the problem that the downloaded file - AND the file saved on the server (currently, I chose the /tmp directory) is empty. It seems like the reason is that epub/index.js has closed the archive, and console logging the "epub" variable in routes/project.js:compile() returns readable: false. It might not be the reason, though, since in the current solution "epub" is similarly pipe'd into "tempFile" after the archive has been closed (is not readable). On the other hand, we are getting ERROR validation emails even on successful downloads ("Error: 1: Error: Command failed: ERROR: /tmp/scripler/prod/2d881ff4-5224-4809-8d76-aea386cca35e.epub: Cannot read header ERROR: /tmp/scripler/prod/2d881ff4-5224-4809-8d76-aea386cca35e.epub: I/O error: zip file is empty"), so maybe those are somehow related.

You can take a look at my non-working attempt here. NB! This requires the following config to be added to the scripler config in nginx:

    location /ebooks/ {
        alias  /tmp/scripler/app/tmp/;
    }

When you fixed #483 you changed the file being returned/shown/downloaded to the user to be named after the project id (because you split up downloading the ebook into the "compile" and the "download" calls).

Any ideas? Do you think we need the third file or can we somehow make either the first or second file be returned to the client with a nice name?

allanmc commented 9 years ago

@mortengf Maybe we can just name the first file with the sanitized name, instead of the project id? Then we still only have 2 files.

I don't think we should have the file stored 3 times.

Another option could also be to let our Express app handle the download instead of just Nginx. In our application we then have control over what filename the user will see in his browser: http://expressjs.com/api.html#res.download

The timing issues with closing the archive we can look at on monday.

mortengf commented 9 years ago

If we name the first file with the sanitized filename, the user will not be able to save two projects with the same name.

Let's see Monday what the best option is.