define all routes

adminDb
remrem 3 years ago
parent b86b9cd568
commit ebc3013b4a

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