Skip to content

Commit

Permalink
Duplicate docs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Smaug6739 committed Dec 22, 2024
1 parent 0323873 commit c920157
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const config = {
max_file_size: 20 * 1024 * 1024, // 20MB
upload_path: resolve(__dirname, '../uploads'),
access_token_expiration: '1800s',
access_token_expiration_ms: 1800 * 1000,
access_token_expiration_ms: 5 * 1000, // 30 minutes
refresh_token_expiration: 7 * 24 * 60 * 60 * 1000,
// in octets
max_user_size: 1000 * 1024 * 1024, // 1GB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ p {
.print-style {
align-items: center;
padding: 0.4rem 0.2rem;
background: none;
.icon,
.description,
.document-tags,
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function connect(username: string, password: string) {
font-size: 1.2rem;
border-radius: 50px;
width: 100%;
background-color: $primary-300;
background-color: $primary-light;
color: white;
&:hover {
background: $primary-dark;
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/signup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async function createAccount(username: string, email: string, password: string)
font-size: 1.2rem;
border-radius: 50px;
width: 100%;
background-color: $primary-300;
background-color: $primary-light;
color: white;
&:hover {
Expand Down
26 changes: 15 additions & 11 deletions frontend/stores/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const requestQueue: { route: string; method: string; body: Object; resolve: (val

export async function makeRequest<T>(route: string, method: string, body: Object, isTreatingQueue: boolean = false): Promise<APIResult<T>> {
console.log(`[API] Requesting [${method}] to /${route}`);

const promise = new Promise<APIResult<T>>((resolve, reject) => {
if (!isTreatingQueue) requestQueue.push({ route, method, body, resolve, reject });
});
Expand All @@ -22,6 +21,10 @@ export async function makeRequest<T>(route: string, method: string, body: Object
const response = await customFetch(method, route, body);
const decoded = await response.json();

if (response.ok && decoded.status === 'success') {
requestQueue.pop();
}

if ((response.status === 401 && decoded.message === 'Bad access token.') || decoded.message === 'Missing token cookies.') {
if (is_getting_new_token) return promise;
console.log('\x1b[41m[AUTH]\x1b[0m Access token invalid. Getting new access token...');
Expand All @@ -43,16 +46,17 @@ export async function makeRequest<T>(route: string, method: string, body: Object

function treatQueue(access_token: boolean = true) {
console.log(`[API] Treating queue with access_token: ${access_token}`);

if (!access_token) {
for (const request of requestQueue) {
request.resolve({ status: 'error', message: 'Failed to fetch.' });
}
useUserStore().post_logout();
navigateTo('/login');
} else {
for (const request of requestQueue) {
makeRequest(request.route, request.method, request.body, true).then(request.resolve).catch(request.reject);
while (requestQueue.length > 0) {
const request = requestQueue.shift();
if (!access_token) {
if (request) {
request.resolve({ status: 'error', message: 'Failed to fetch.' });
requestQueue.length = 0;
useUserStore().post_logout();
navigateTo('/login');
}
} else if (request) {
makeRequest(request.route, request.method, request.body, true).then(request.resolve).catch(console.info);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/stores/documents.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const useDocumentsStore = defineStore('documents', {
return new Promise(async (resolve, reject) => {
const request = await makeRequest('documents', 'POST', doc);
if (request.status == 'success') {
this.documents.push({ ...(request.result as DB_Document), type: 'document' });
this.documents.push({ ...(request.result as DB_Document), type: 'document', partial: false });
resolve(request.result as DB_Document);
} else reject(request.message);
});
Expand Down

0 comments on commit c920157

Please sign in to comment.