@graffiticode/basis 1.5.1 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/share.js +0 -73
package/package.json
CHANGED
package/src/share.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
|
|
2
|
-
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
3
1
|
/*
|
|
4
2
|
* Copyright 2013 Art Compiler LLC
|
|
5
3
|
*
|
|
@@ -77,7 +75,6 @@
|
|
|
77
75
|
|
|
78
76
|
*/
|
|
79
77
|
|
|
80
|
-
import Hashids from 'hashids';
|
|
81
78
|
import https from 'https';
|
|
82
79
|
|
|
83
80
|
export const messages = {};
|
|
@@ -116,76 +113,6 @@ export const reserveCodeRange = function (first, last, moduleName) {
|
|
|
116
113
|
reservedCodes.push({first: first, last: last, name: moduleName});
|
|
117
114
|
}
|
|
118
115
|
|
|
119
|
-
const hashids = new Hashids("Art Compiler LLC"); // This string shall never change!
|
|
120
|
-
export const decodeID = (id) => {
|
|
121
|
-
// console.log("[1] decodeID() >> " + id);
|
|
122
|
-
// 123456, 123+534653+0, Px4xO423c, 123+123456+0+Px4xO423c, Px4xO423c+Px4xO423c
|
|
123
|
-
if (id === undefined) {
|
|
124
|
-
id = "0";
|
|
125
|
-
}
|
|
126
|
-
if (Number.isInteger(id)) {
|
|
127
|
-
id = "" + id;
|
|
128
|
-
}
|
|
129
|
-
if (Array.isArray(id)) {
|
|
130
|
-
// Looks like it is already decoded.
|
|
131
|
-
assert(Number.isInteger(id[0]) && Number.isInteger(id[1]));
|
|
132
|
-
return id;
|
|
133
|
-
}
|
|
134
|
-
assert(typeof id === "string", "Invalid id " + id);
|
|
135
|
-
id = id.replace(/\+/g, " ");
|
|
136
|
-
let parts = id.split(" ");
|
|
137
|
-
let ids = [];
|
|
138
|
-
// Concatenate the first two integer ids and the last hash id. Everything
|
|
139
|
-
// else gets erased.
|
|
140
|
-
for (let i = 0; i < parts.length; i++) {
|
|
141
|
-
let n;
|
|
142
|
-
if (ids.length > 2) {
|
|
143
|
-
// Found the head, now skip to the last part to get the tail.
|
|
144
|
-
ids = ids.slice(0, 2);
|
|
145
|
-
i = parts.length - 1;
|
|
146
|
-
}
|
|
147
|
-
if (Number.isInteger(n = +parts[i])) {
|
|
148
|
-
ids.push(n);
|
|
149
|
-
} else {
|
|
150
|
-
ids = ids.concat(hashids.decode(parts[i]));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
// Fix short ids.
|
|
154
|
-
if (ids.length === 1) {
|
|
155
|
-
ids = [0, ids[0], 0];
|
|
156
|
-
} else if (ids.length === 2) {
|
|
157
|
-
ids = [0, ids[0], 113, ids[1], 0];
|
|
158
|
-
} else if (ids.length === 3 && ids[2] !== 0) {
|
|
159
|
-
ids = [ids[0], ids[1], 113, ids[2], 0];
|
|
160
|
-
}
|
|
161
|
-
// console.log("[2] decodeID() << " + JSON.stringify(ids));
|
|
162
|
-
return ids;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export const encodeID = (ids) => {
|
|
166
|
-
// console.log("[1] encodeID() >> " + JSON.stringify(ids));
|
|
167
|
-
let length = ids.length;
|
|
168
|
-
if (length >= 3 &&
|
|
169
|
-
// [0,0,0] --> "0"
|
|
170
|
-
+ids[length - 3] === 0 &&
|
|
171
|
-
+ids[length - 2] === 0 &&
|
|
172
|
-
+ids[length - 1] === 0) {
|
|
173
|
-
ids = ids.slice(0, length - 2);
|
|
174
|
-
length = ids.length;
|
|
175
|
-
}
|
|
176
|
-
if (length === 1) {
|
|
177
|
-
if (+ids[0] === 0) {
|
|
178
|
-
return "0";
|
|
179
|
-
}
|
|
180
|
-
ids = [0, +ids[0], 0];
|
|
181
|
-
} else if (length === 2) {
|
|
182
|
-
ids = [0, +ids[0], 113, +ids[1], 0];
|
|
183
|
-
}
|
|
184
|
-
let id = hashids.encode(ids);
|
|
185
|
-
// console.log("[2] encodeID() << " + id);
|
|
186
|
-
return id;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
116
|
function postAuth(path, data, resume) {
|
|
190
117
|
let encodedData = JSON.stringify(data);
|
|
191
118
|
var options = {
|