-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only download cache for system languages and English #420
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d14c14
Fix: Download Only the files for Required Language And English as Bac…
vivekjoshi556 7a09771
Test: Added Tests to Check for Downloads based on different Language …
vivekjoshi556 aaa9947
Fix: Fixed Test Cases | Feat: Included use of LANGUAGE env variable
vivekjoshi556 fadd927
Fix: Review Changes
vivekjoshi556 04a8cf2
Promise.all change
MasterOdin 6a4f964
Split utils tests to its own file
MasterOdin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,44 @@ | ||
'use strict'; | ||
|
||
const unzip = require('node-unzip-2'); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const unzip = require('adm-zip'); | ||
const config = require('./config'); | ||
const axios = require('axios'); | ||
|
||
// Downloads the zip file from github and extracts it to folder | ||
exports.download = (path) => { | ||
const url = config.get().repository; | ||
exports.download = (loc, lang) => { | ||
// If the lang is english then keep the url simple, otherwise add language. | ||
const suffix = (lang === 'en' ? '' : '.' + lang); | ||
const url = config.get().repositoryBase + suffix + '.zip'; | ||
const folderName = path.join(loc, 'pages' + suffix); | ||
const REQUEST_TIMEOUT = 10000; | ||
|
||
// Creating the extractor | ||
const extractor = unzip.Extract({ path }); | ||
|
||
let req = axios({ | ||
return axios({ | ||
method: 'get', | ||
url: url, | ||
responseType: 'stream', | ||
headers: { 'User-Agent' : 'tldr-node-client' } | ||
}).then(function (response) { | ||
response.data.pipe(extractor); | ||
}); | ||
headers: { 'User-Agent' : 'tldr-node-client' }, | ||
timeout: REQUEST_TIMEOUT, | ||
}).then((response) => { | ||
return new Promise((resolve, reject) => { | ||
let fileName = path.join(loc, 'download_' + lang + '.zip'); | ||
|
||
return new Promise((resolve, reject) => { | ||
req.catch((err) => { | ||
reject(err); | ||
}); | ||
extractor.on('error', () => { | ||
reject(new Error('Cannot update from ' + url)); | ||
}); | ||
extractor.on('close', () => { | ||
resolve(); | ||
const writer = fs.createWriteStream(fileName); | ||
response.data.pipe(writer); | ||
|
||
writer.on('finish', () => { | ||
writer.end(); | ||
const zip = new unzip(fileName); | ||
|
||
zip.extractAllTo(folderName, true); | ||
fs.unlinkSync(fileName); | ||
resolve(); | ||
}).on('error', (err) => { | ||
reject(err); | ||
}); | ||
}); | ||
}).catch((err) => { | ||
return Promise.reject(err); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding this, we recently added support for the English archive in the same format
tldr-pages-en.zip
(after a request from tealdeer's maintainer). Can it be implemented here instead? (This will officially land in the upcoming client spec 2.1)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure should be easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be noted that only the archive name should be generalized here, while still leaving in place that the english archive is extracted to the
pages
directory. Changing that behavior is a much larger one, which should be done in a separate PR that's focused purely on that, as will also have to take into account backwards compatibility.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, won't it be better to handle this entirely in the same (other) PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say so, but not sure how much @kbdharun wants to see the archive name changed here. The old zip will continue to work anyway for the time being that it's not exactly urgent to make that change either.