-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
125 lines (110 loc) · 3.61 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const fs = require("fs");
module.exports = function () {
this.ZONE_BOOK_LIST_KEY_PREFIX = "ZONE_BOOK_LIST_";
this.BOOK_ZONE_KEY_PREFIX = "BOOK_ZONE_";
this.PARCEL_ACCOUNT_NUMBER_PREFIX = "ACCOUNT_NUMBER_";
this.TREASURER_BALANCE_DUE_PREFIX = "TREASURER_BALANCE_DUE_";
this.BALANCE_DUE_FILENAME = "balance_due_extract.txt";
this.SHERIFF_EDIT_HISTORY_PREFIX = "SHERIFF_EDIT_HISTORY_";
this.ZONE_EDIT_HISTORY_PREFIX = "ZONE_EDIT_HISTORY_";
this.ZONE_ROTATION_PREFIX = "ZONE_ROTATION_";
this.EDIT_HISTORY_FILENAME = "edit_history.tsv";
this.TYLER_DATA_FILENAME = "tyler.csv";
this.TYLER_DATA_PREFIX = "TYLER_DATA_";
const googleParams = JSON.parse(
fs.readFileSync(__dirname + "/googleAuth.json")
);
this.GOOGLEAUTH = {
type: "OAuth2",
user: "apachecountyfeedback@gmail.com",
clientId: googleParams.CLIENT_ID,
clientSecret: googleParams.CLIENT_SECRET,
refreshToken: googleParams.REFRESH_TOKEN,
redirectUri: googleParams.REDIRECT_URI,
};
// S3 Access
const s3Params = JSON.parse(fs.readFileSync(__dirname + "/s3params.json"));
this.S3_ACCESS = s3Params.accessId;
this.S3_SECRET = s3Params.secret;
this.S3_BUCKET_NAME = s3Params.bucketName;
const AWS = require("aws-sdk");
const s3 = new AWS.S3({
accessKeyId: S3_ACCESS,
secretAccessKey: S3_SECRET,
});
this.uploadJSONToS3 = (relativeFilePath, fileContent, uploadCallback) => {
// Setting up S3 upload parameters
const params = {
Bucket: S3_BUCKET_NAME,
Key: "gis-data-api/" + relativeFilePath,
Body: fileContent,
};
// Uploading files to the bucket
s3.upload(params, uploadCallback);
};
this.uploadFileToS3 = (relativeFilePath, file, uploadCallback) => {
const key = "gis-data-api/" + relativeFilePath;
var params = {
Bucket: S3_BUCKET_NAME,
Key: key,
Body: fs.createReadStream(file.path),
};
s3.putObject(params, function (err, data) {
if (err) {
console.log("Error at uploadFileToS3 function", err);
} else {
uploadCallback(err, data);
}
});
};
this.uploadFileAtPathToS3 = (relativeFilePath, filePath, uploadCallback) => {
const key = "gis-data-api/" + relativeFilePath;
var params = {
Bucket: S3_BUCKET_NAME,
Key: key,
Body: fs.createReadStream(filePath),
};
s3.putObject(params, function (err, data) {
if (err) {
console.log("Error at uploadFileAtPathToS3 function", err);
} else {
uploadCallback(err, data);
}
});
};
/**
*
* @param {*} relativeFilePath
* @param {*} stream Readable
* @param {*} uploadCallback
*/
this.uploadStreamToS3 = (relativeFilePath, stream, uploadCallback) => {
const key = "gis-data-api/" + relativeFilePath;
var params = {
Bucket: S3_BUCKET_NAME,
Key: key,
Body: stream,
ContentLength: stream.readableLength,
};
s3.putObject(params, function (err, data) {
if (err) {
console.log("Error at uploadStreamToS3 function", err);
} else {
uploadCallback(err, data);
}
});
};
this.normalizeParcelNumber = function (parcel_num) {
if (parcel_num == null) return null;
var sanitized_parcel = parcel_num.replace("-", "");
while (sanitized_parcel.indexOf("-") >= 0) {
sanitized_parcel = sanitized_parcel.replace("-", ""); // Search ignores hyphens
}
sanitized_parcel = sanitized_parcel.toUpperCase(); // Search ignores case
return sanitized_parcel;
};
this.normalizeAccountNumber = function (account_num) {
if (account_num == null) return null;
return PARCEL_ACCOUNT_NUMBER_PREFIX + account_num;
};
};