-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save tiles to S3 when not pregenerated
- Loading branch information
1 parent
0f7affe
commit a32f8ff
Showing
17 changed files
with
316 additions
and
160 deletions.
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
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,12 +1,26 @@ | ||
const axios = require('axios').default; | ||
const AWS = require('aws-sdk'); | ||
|
||
module.exports = async params => { | ||
const url = encodeURI(`${process.env.TILES_URL}/${params.join('/')}.png`); | ||
const s3 = new AWS.S3({ apiVersion: '2006-03-01' }); | ||
|
||
const { data } = await axios.get(url, { | ||
headers: { Accept: 'image/*' }, | ||
responseType: 'arraybuffer', | ||
}); | ||
/** | ||
* Get a pregenerated tile based on its path | ||
* @param {string} path Path of the tile | ||
* @returns {Promise<AWS.S3.Body>} | ||
*/ | ||
module.exports = path => { | ||
const bucketParams = { | ||
Bucket: process.env.AWS_BUCKET_NAME, | ||
Key: `tiles/${path}.png`, | ||
}; | ||
|
||
return new Promise((resolve, reject) => { | ||
s3.getObject(bucketParams, function(err, data) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
|
||
return data; | ||
resolve(data.Body); | ||
}); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const AWS = require('aws-sdk'); | ||
|
||
const s3 = new AWS.S3({ apiVersion: '2006-03-01' }); | ||
|
||
/** | ||
* Save a tile in S3 | ||
* @param {string} path Path of the tile | ||
* @param {Buffer} file Tile | ||
*/ | ||
module.exports = (path, file) => { | ||
return new Promise((resolve, reject) => { | ||
s3.putObject( | ||
{ | ||
Key: `tiles/${path}.png`, | ||
Bucket: process.env.AWS_BUCKET_NAME, | ||
ContentType: 'image/png', | ||
Body: file, | ||
}, | ||
function(err) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
|
||
resolve(); | ||
} | ||
); | ||
}); | ||
}; |
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
Oops, something went wrong.