UI: file list improvements
This commit is contained in:
+5
-3
@@ -3,6 +3,7 @@
|
||||
#include "main.h"
|
||||
#include "session.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@@ -10,15 +11,16 @@
|
||||
void process_client_command(char *line, session *sess, server_data_t *s_d) {
|
||||
char arg_1[32];
|
||||
char arg_2[32];
|
||||
int res;
|
||||
uint32_t res;
|
||||
uint32_t limit, page;
|
||||
|
||||
sscanf(line, "%s %s", arg_1, arg_2);
|
||||
|
||||
if (!strcmp(arg_1, "file")) {
|
||||
/* LIST */
|
||||
if (!strcmp(arg_2, "list")) {
|
||||
file_list(sess, s_d, 1);
|
||||
sess->state = OP_FILE_LIST;
|
||||
sscanf(line, "%*s %*s %u %u", &limit, &page);
|
||||
file_list(sess, s_d, limit, page);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,6 +127,9 @@ int32_t db_user_auth(i_auth_t *c, o_auth_t *r) {
|
||||
|
||||
const char *pass = PQgetvalue(res, 0, 2);
|
||||
string_to_SHA256( c->pass, passHashed);
|
||||
if (pass == NULL) {
|
||||
/* TODO: return */
|
||||
}
|
||||
if (!strcmp(passHashed, pass)) {
|
||||
r->privileges = PQgetvalue(res, 0, 3)[0];
|
||||
r->uid = atoi(PQgetvalue(res, 0, 0));
|
||||
|
||||
+7
-23
@@ -39,23 +39,7 @@ void clear_list(fl_t *start) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) {
|
||||
uint64_t num;
|
||||
char op_symbol;
|
||||
|
||||
if (!sscanf(line, "%c %lu", &op_symbol, &num))
|
||||
return 0;
|
||||
|
||||
switch (op_symbol) {
|
||||
case 'p':
|
||||
file_list(sess, s_d, num);
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void file_list(session *sess, server_data_t *s_d, uint64_t page) {
|
||||
void file_list(session *sess, server_data_t *s_d, uint32_t limit, uint32_t page) {
|
||||
char list_end[] = "list_end\n";
|
||||
fl_t *fl_start, *fl_current;
|
||||
char item_h[256];
|
||||
@@ -71,22 +55,22 @@ void file_list(session *sess, server_data_t *s_d, uint64_t page) {
|
||||
sess->fl_current = NULL;
|
||||
}
|
||||
|
||||
args.limit = 15;
|
||||
args.offset = 15 * (page - 1);
|
||||
args.limit = limit;
|
||||
args.offset = limit * (page - 1);
|
||||
args.sort_by = ID;
|
||||
args.sort_direction = ASC;
|
||||
|
||||
count = db_get_files_data(&args, &fl_start, &full_count);
|
||||
char page_info[256];
|
||||
|
||||
pages_count = full_count / 15;
|
||||
pages_count = full_count / limit;
|
||||
if (!pages_count)
|
||||
pages_count = 1;
|
||||
if (pages_count % 15)
|
||||
if (pages_count % limit)
|
||||
pages_count++;
|
||||
|
||||
sprintf(page_info, "=== PAGE %lu/%lu COUNT: %lu/%lu ===\n", page, pages_count,
|
||||
count, full_count - (page - 1) * 15);
|
||||
sprintf(page_info, "=== PAGE %u/%lu COUNT: %lu/%lu ===\n", page, pages_count,
|
||||
count, full_count - (page - 1) * limit);
|
||||
|
||||
if (!fl_start)
|
||||
return;
|
||||
|
||||
+1
-2
@@ -2,8 +2,7 @@
|
||||
#define FILEP_H
|
||||
#include "main.h"
|
||||
void clear_list(fl_t *start);
|
||||
uint32_t navigate_list(session *sess, char *line, server_data_t *s_d) ;
|
||||
void file_list(session *, server_data_t *, uint64_t page);
|
||||
void file_list(session *, server_data_t *, uint32_t limit, uint32_t page);
|
||||
int file_send_prepare(session *, char *, server_data_t *);
|
||||
enum f_actions {
|
||||
F_UPLOAD,
|
||||
|
||||
@@ -18,7 +18,6 @@ enum sess_states {
|
||||
OP_EDIT_FILE,
|
||||
OP_DOWNLOAD,
|
||||
OP_EDIT_USER,
|
||||
OP_FILE_LIST,
|
||||
OP_LOGIN_USR,
|
||||
OP_LOGIN_PSS,
|
||||
OP_LOGIN_ANON,
|
||||
|
||||
@@ -159,11 +159,6 @@ void perform_session_action(session *sess, char *line, server_data_t *s_d) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OP_FILE_LIST:
|
||||
if (!navigate_list(sess, line, s_d)) {
|
||||
process_client_command(line, sess, s_d);
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* } */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user