define all routes

adminDb
remrem 3 years ago
parent b86b9cd568
commit ebc3013b4a

@ -1,27 +1,25 @@
import 'dart:io'; import 'dart:io';
import 'dart:async'; import 'package:r_api/api.dart';
import 'package:shelf/shelf.dart'; import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart'; import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart'; import 'package:shelf_router/shelf_router.dart';
import 'package:path/path.dart' as path;
// Configure routes. // Configure routes.
final _router = Router() final _router = Router()
..get('/', _rootHandler) // GET
..get('/echo/<message>', _echoHandler) ..get('/', API.rootHandler)
..get('/down/<file>', _fileHandler); ..get('/auth', API.authenticator)
..get('/user/down-password-file', API.downloadPasswordDb)
Response _rootHandler(Request req) { // POST
return Response.ok('Hello, World!\n'); ..post('/user/create-account', API.createAccount)
} // PUT
..put('/user/change-master-password', API.changeMasterPassword)
Response _echoHandler(Request req) { ..put('/user/up-password-file', API.uploadPasswordDb)
print(req.url); ..put('/user/change-mail', API.changeMail)
final message = req.params['message']; // DELETE
return Response.ok('$message\n'); ..delete('/user/delete-account', API.deleteAccount);
}
/*
Response _fileHandler(Request req) { Response _fileHandler(Request req) {
final String _basePath = '/home/hel/Projets/r_api/res/'; final String _basePath = '/home/hel/Projets/r_api/res/';
final String reqFile = path.join(_basePath, req.params['file']); final String reqFile = path.join(_basePath, req.params['file']);
@ -38,6 +36,7 @@ Future<bool> fileExist(String path) {
print(exist); print(exist);
return exist; return exist;
} }
*/
void main(List<String> args) async { void main(List<String> args) async {
// Use any available host or container IP (usually `0.0.0.0`). // Use any available host or container IP (usually `0.0.0.0`).

@ -0,0 +1,77 @@
import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
class API {
/*---------------|
|-------GET------|
|---------------*/
// Default response for /
static Response rootHandler(Request req) {
return Response.ok('Greetings from PassWorld!\n');
}
// Request for authentification
// Compare given cyphered_hash_password with db cyphered_hash_password
// Return boolean -> true (hash match) false (no match)
static Response authenticator(Request req) {
final mail = req.params['mail'];
final password = req.params['cyphered_password_hash'];
return Response.ok('true');
}
// Request sqlite password db
// Check auth
// Return sqlite file
static Response downloadPasswordDb(Request req) {
final mail = req.params['mail'];
final password = req.params['cyphered_password_hash'];
// Database query -> return file (List<int>)
// Create stream from List<int>
// Rename file -> db_password_<mail>_<date>
// Send file
return Response.ok("");
/*
Stream<List<int>> fileStream = file.openRead();
return Response.ok(fileStream, headers: {
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment, filename="$reqFile"'
});
*/
}
/*---------------|
|------POST------|
|---------------*/
static Response createAccount(Request req) {
return Response.ok("");
}
/*---------------|
|-------PUT------|
|---------------*/
static Response changeMasterPassword(Request req) {
return Response.ok("master password chnaged");
}
static Response changeMail(Request req) {
return Response.ok("master password chnaged");
}
static Response uploadPasswordDb(Request req) {
return Response.ok("");
}
/*---------------|
|-----DELETE-----|
|---------------*/
static Response deleteAccount(Request req) {
return Response.ok("");
}
}
Loading…
Cancel
Save