Skip to content

Commit e72d3c2

Browse files
committed
Fix download transfer locally
1 parent 414a274 commit e72d3c2

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1515
## [Unreleased]
1616
### Fixed
1717
- paymentRequest duplicated payment
18+
- download transfer locally
1819

1920
## [0.6.5] - 2024-06-28
2021
### Added

src/.clasp.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"scriptId":"1JAupf57mwkjPaC3FFC8Ydx-yo6LkoIjnIrpQx2_95JenFfQ0G2ov4rbO","rootDir":"/Users/luis.almeida/Documents/starkbank/google-sheets/src"}
1+
{"scriptId":"199zM22Q3FVHJK5EOZtrz7EQ7bH5wm_vnQCu-YVI7kOz6N455TDq-XmMq"}

src/sdkViewTransfer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function TransferDownloadAllLocal(){
120120
}
121121

122122

123-
function TransferDownloadBase64Encoded(id){
123+
function TransferDownloadBase64Encoded(id="6560940799557632"){
124124
let blob = TransferDownload(id);
125125
return {
126126
id: id,

src/utilsRequest.js

+53-37
Original file line numberDiff line numberDiff line change
@@ -102,53 +102,69 @@ function parseResponse(responseApi) {
102102
}
103103

104104

105-
function fetchBuffer(path, method = 'GET', payload = null, query = null, version = 'v2') {
105+
function fetchBuffer(path, method='GET', payload=null, query=null, version="v2", environment=null, privateKeyPem=null, challengeId=null) {
106106
let user = new getDefaultUser();
107-
let hostname = getHostname(user.environment.toLowerCase(), version);
108-
let options = {method: method};
107+
if (!user.privateKey) {
108+
throw JSON.stringify({"message": "Erro de autenticação! Por favor, faça login novamente."});
109+
}
110+
if (!environment) {
111+
environment = environment || user.environment.toLowerCase();
112+
}
113+
let hostname = getHostname(environment, version);
114+
let options = {
115+
method: method,
116+
muteHttpExceptions: true,
117+
};
109118
let url = hostname + path;
110119

111120
if (query) {
112-
let queryString = '';
113-
let separator = '?';
114-
for (let key in query) {
115-
if (query[key]) {
116-
queryString += separator + key + '=' + query[key];
117-
separator = '&';
121+
let queryString = '';
122+
let separator = '?';
123+
for (let key in query) {
124+
if (query[key]) {
125+
queryString += separator + key + '=' + query[key];
126+
separator = '&';
127+
}
118128
}
119-
}
120-
url += queryString;
129+
url += queryString;
121130
}
122131

123-
paths = ["/session", "/boleto-payment"]
124-
125-
if (paths.includes(path) && method != "GET") {
126-
var accessId = KeyGen.generateMemberAccessId(user.workspaceId, user.email)
127-
} else {
128-
var accessId = user.accessId;
129-
}
130-
131-
let accessTime = Math.round((new Date()).getTime() / 1000).toString();
132-
options['headers'] = {
133-
'Access-Id': accessId,
134-
'User-Agent': 'GoogleSheets-SDK-0.4.3',
135-
'Accept-Language': 'pt-BR',
136-
'Content-Type': 'application/json',
137-
'Access-Time': accessTime
138-
};
139-
140-
let body = JSON.stringify(payload);
141-
if (!payload) {
142-
body = "";
143-
}
132+
if (privateKeyPem) {
133+
var accessId = KeyGen.generateMemberAccessId(user.workspaceId, user.email)
134+
} else {
135+
var accessId = user.accessId;
136+
}
144137

145-
options['payload'] = body;
146-
147138
if (!privateKeyPem) {
148-
var privateKeyPem = user.privateKey;
139+
var privateKeyPem = user.privateKey;
149140
}
150-
151-
let message = accessId + ':' + accessTime + ':' + body;
141+
142+
let accessTime = Math.round((new Date()).getTime() / 1000).toString();
143+
options['headers'] = {
144+
'Access-Id': accessId,
145+
'User-Agent': 'App-StarkBank-GSheets-v0.6.5b',
146+
'User-Agent-Override': 'App-StarkBank-GSheets-v0.6.5b',
147+
'PlatFormId' : 'gsheets',
148+
'PlatFormVersion' : '0.6.5',
149+
'Accept-Language': 'pt-BR',
150+
'Content-Type': 'application/pdf',
151+
'Access-Time': accessTime
152+
};
153+
154+
let body = ""
155+
if (payload) {
156+
body = payload;
157+
}
158+
159+
options['payload'] = body;
160+
161+
let message = accessId + ':' + accessTime + ':' + body
162+
163+
if (challengeId) {
164+
message += ":" + challengeId
165+
options['headers']['Access-Challenge-Ids'] = challengeId
166+
}
167+
152168
let signature = easySign(message, privateKeyPem);
153169
options['headers']['Access-Signature'] = signature;
154170

0 commit comments

Comments
 (0)