Skip to content
Open
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
10 changes: 9 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ var argv = require('yargs')
.alias('a', 'apikey')
.describe('a', 'specify cartodb apikey'.yellow)
.default('a', null, '$CARTODB_API_KEY')
.alias('s', 'subdomainless')
.boolean('s')
.default('s', undefined)
.describe('s', 'whether to use subdomainless url mode'.yellow)
.alias('D', 'domain')
.describe('D', 'whether to use the non default domain'.yellow)
.example('$0 -f foo.geojson', 'uploads the file foo.geojson'.green)
.example('$0 -n foo.geojson', 'sets name of the file, if -f is not specified uses stdin '.green)
.help('h', 'Show Help'.yellow)
Expand Down Expand Up @@ -68,7 +74,9 @@ if (argv.n) {

instream.pipe(uploader({
user: user,
key: key
key: key,
domain: argv.D,
subdomainless: argv.s
}, name, function (err, resp) {
if (err) {
process.stdout.write(JSON.stringify(err, false, 2));
Expand Down
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var once = require('once');
var zlib = require('zlib');
module.exports = exports = cartodbUploader;
function getUploadState(credentials, destination, callback) {
var rawUrl = 'https://' + credentials.user + '.carto.com/api/v1/imports/' + destination + '?' + qs.stringify({
api_key: credentials.key
var rawUrl = createUrlBase(credentials) + '/api/v1/imports/' + destination + '?' + qs.stringify({
api_key: credentials.key
});
https.get(rawUrl, function (res) {
var data = [];
Expand Down Expand Up @@ -61,7 +61,7 @@ function cartodbUploader(credentials, fileName, callback) {
contentType: 'application/octet-stream'
});
form.on('error', callback);
var fullUrl = 'https://' + credentials.user + '.carto.com/api/v1/imports?';
var fullUrl = createUrlBase(credentials) + '/api/v1/imports?';
//var fullUrl = 'http://cartodb.calvin:8080/';
fullUrl += qs.stringify({
api_key: credentials.key
Expand Down Expand Up @@ -127,3 +127,17 @@ function uploadGeoJson(credentials, destination, callback) {
.pipe(cartodbUploader(credentials, destination + '.geojson', callback));
return inStream;
}
function createUrlBase(credentials) {
if (!credentials.domain && !credentials.subdomainless) {
return `https://${credentials.user}.carto.com`;
}
if (credentials.domain) {
if (credentials.subdomainless) {
return `https://${credentials.domain}/user/${credentials.user}`;
} else {
return `https://${credentials.user}.${credentials.domain}`;
}
} else if (credentials.subdomainless) {
return `https://carto.com/user/${credentials.user}`;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"geojson-stream": "0.0.0",
"once": "^1.3.2",
"readable-stream": "^2.0.2",
"yargs": "^3.9.1"
"yargs": "^14.1.0"
},
"devDependencies": {
"jsonstream3": "^3.0.0",
Expand Down