idk
continuous-integration/drone/push Build is passing Details

master
remrem 2 years ago
parent 312e73de15
commit 18f65d6555

@ -137,21 +137,32 @@ class API {
// Upload sqlite password file // Upload sqlite password file
static Future<Response> uploadPasswordDb(Request req) async { static Future<Response> uploadPasswordDb(Request req) async {
final List<String> required = ["email", "password", "file"]; final List<String> required = ["email", "password", "file"];
final body = await bodyToJson(req); // await is needed even if IDE say no final body = await bodyToJson(req);
if (await checkRequiredFields(required, body)) {
try {
if (await checkAuthentication(body[required[0]], body[required[1]])) {
String fileAsBytes = body[required[2]]; String fileAsBytes = body[required[2]];
var arrayBytes = fileAsBytes.split(','); var arrayBytes = fileAsBytes.split(',');
arrayBytes.removeLast(); arrayBytes.removeLast();
var arrayBytes2 = arrayBytes.map(int.parse).toList(); List<int> arrayBytes2 = arrayBytes.map(int.parse).toList();
await AccountsToPostgres.updatePasswordFile(
await AccountsToPostgres.updatePasswordFile(body[required[0]], arrayBytes2); body[required[0]], arrayBytes2);
} else {
File file = File("./passfile"); return Response(403); // 403 (Forbidden)
file.writeAsBytes(arrayBytes2); }
} catch (e, s) {
print(await file.stat()); print("Exception $e");
return Response.ok("API: file received"); print("Stacktrace $s");
return Response(409,
body: 'There was a problem with upload'); // 409 (Conflict)
}
print("✅ PassWord file succesfully uploaded");
return Response(201,
body: 'PassWord file succesfully uploaded'); // 20 (OK)
} else {
return Response.badRequest(body: 'Bad request'); // 400 (Bad Request)
}
} }
// Download sqlite password file // Download sqlite password file
@ -159,13 +170,25 @@ class API {
final List<String> required = ["email", "password"]; final List<String> required = ["email", "password"];
final body = await bodyToJson(req); final body = await bodyToJson(req);
if (await checkRequiredFields(required, body)) {
try {
if (await checkAuthentication(body[required[0]], body[required[1]])) {
List<int> file = List<int> file =
await AccountsToPostgres.getPasswordFile(body[required[0]]); await AccountsToPostgres.getPasswordFile(body[required[0]]);
for (int i in file) { print("✅ PassWord file succesfully downloaded");
print(i); return Response(200, body: file.toString());
} else {
return Response(403); // 403 (Forbidden)
}
} catch (e, s) {
print("Exception $e");
print("Stacktrace $s");
return Response(409,
body: 'There was a problem with upload'); // 409 (Conflict)
} // 200 (OK)
} else {
return Response.badRequest(body: 'Bad request'); // 400 (Bad Request)
} }
return Response.ok(file.toString());
} }
// Check if required fields are in req body // Check if required fields are in req body

Loading…
Cancel
Save