feat: update API controllers, validations, and Vue components
All checks were successful
CI / container-job (push) Successful in 49s
All checks were successful
CI / container-job (push) Successful in 49s
- Modified Api/Authors.Controller.ts to use only personal types and sort by dataset_count. - Completely rewritten AvatarController.ts. - Added new Api/CollectionsController.ts for querying collections and collection_roles. - Modified Api/DatasetController.ts to preload titles, identifier and order by server_date_published. - Modified FileController.ts to serve files from /storage/app/data/ instead of /storage/app/public. - Added new Api/UserController for requesting submitters (getSubmitters). - Improved OaiController.ts with performant DB queries for better ResumptionToken handling. - Modified Submitter/DatasetController.ts by adding a categorize method for library classification. - Rewritten ResumptionToken.ts. - Improved TokenWorkerService.ts to utilize browser fingerprint. - Edited dataset.ts by adding the doiIdentifier property. - Enhanced person.ts to improve the fullName property. - Completely rewritten AsideMenuItem.vue component. - Updated CarBoxClient.vue to use TypeScript. - Added new CardBoxDataset.vue for displaying recent datasets on the dashboard. - Completely rewritten TableSampleClients.vue for the dashboard. - Completely rewritten UserAvatar.vue. - Made small layout changes in Dashboard.vue. - Added new Category.vue for browsing scientific collections. - Adapted the pinia store in main.ts. - Added additional routes in start/routes.ts and start/api/routes.ts. - Improved referenceValidation.ts for better ISBN existence checking. - NPM dependency updates.
This commit is contained in:
parent
36cd7a757b
commit
b540547e4c
34 changed files with 1757 additions and 1018 deletions
|
@ -4,6 +4,7 @@ export default class ResumptionToken {
|
|||
private _resumptionId = '';
|
||||
private _startPosition = 0;
|
||||
private _totalIds = 0;
|
||||
private _queryParams: Record<string, any> = {};
|
||||
|
||||
get key(): string {
|
||||
return this.metadataPrefix + this.startPosition + this.totalIds;
|
||||
|
@ -48,4 +49,12 @@ export default class ResumptionToken {
|
|||
set totalIds(totalIds: number) {
|
||||
this._totalIds = totalIds;
|
||||
}
|
||||
|
||||
get queryParams(): Record<string, any> {
|
||||
return this._queryParams;
|
||||
}
|
||||
|
||||
set queryParams(params: Record<string, any>) {
|
||||
this._queryParams = params;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,6 @@ export default abstract class TokenWorkerContract {
|
|||
abstract connect(): void;
|
||||
abstract close(): void;
|
||||
abstract get(key: string): Promise<ResumptionToken | null>;
|
||||
abstract set(token: ResumptionToken): Promise<string>;
|
||||
abstract set(token: ResumptionToken, browserFingerprint: string): Promise<string>;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,14 +40,64 @@ export default class TokenWorkerService implements TokenWorkerContract {
|
|||
return result !== undefined && result !== null;
|
||||
}
|
||||
|
||||
public async set(token: ResumptionToken): Promise<string> {
|
||||
const uniqueName = await this.generateUniqueName();
|
||||
/**
|
||||
* Simplified set method that stores the token using a browser fingerprint key.
|
||||
* If the token for that fingerprint already exists and its documentIds match the new token,
|
||||
* then the fingerprint key is simply returned.
|
||||
*/
|
||||
public async set(token: ResumptionToken, browserFingerprint: string): Promise<string> {
|
||||
// Generate a 15-digit unique number string based on the fingerprint
|
||||
const uniqueNumberKey = this.createUniqueNumberFromFingerprint(browserFingerprint, token.documentIds, token.totalIds);
|
||||
// Optionally, you could prefix it if desired, e.g. 'rs_' + uniqueNumberKey
|
||||
const fingerprintKey = uniqueNumberKey;
|
||||
|
||||
// const fingerprintKey = `rs_fp_${browserFingerprint}`;
|
||||
const existingTokenString = await this.cache.get(fingerprintKey);
|
||||
|
||||
if (existingTokenString) {
|
||||
const existingToken = this.parseToken(existingTokenString);
|
||||
if (this.arraysAreEqual(existingToken.documentIds, token.documentIds)) {
|
||||
return fingerprintKey;
|
||||
}
|
||||
}
|
||||
|
||||
const serialToken = JSON.stringify(token);
|
||||
await this.cache.setEx(uniqueName, this.ttl, serialToken);
|
||||
return uniqueName;
|
||||
await this.cache.setEx(fingerprintKey, this.ttl, serialToken);
|
||||
return fingerprintKey;
|
||||
}
|
||||
|
||||
// Updated helper method to generate a unique key based on fingerprint and documentIds
|
||||
private createUniqueNumberFromFingerprint(browserFingerprint: string, documentIds: number[], totalIds: number): string {
|
||||
// Combine the fingerprint, document IDs and totalIds to produce the input string
|
||||
const combined = browserFingerprint + ':' + documentIds.join('-') + ':' + totalIds;
|
||||
// Simple hash algorithm
|
||||
let hash = 0;
|
||||
for (let i = 0; i < combined.length; i++) {
|
||||
hash = (hash << 5) - hash + combined.charCodeAt(i);
|
||||
hash |= 0; // Convert to 32-bit integer
|
||||
}
|
||||
// Ensure positive number and limit it to at most 15 digits
|
||||
const positiveHash = Math.abs(hash) % 1000000000000000;
|
||||
// Pad with trailing zeros to ensure a 15-digit string
|
||||
return positiveHash.toString().padEnd(15, '0');
|
||||
}
|
||||
|
||||
// Add a helper function to compare two arrays of numbers with identical order
|
||||
private arraysAreEqual(arr1: number[], arr2: number[]): boolean {
|
||||
if (arr1.length !== arr2.length) {
|
||||
return false;
|
||||
}
|
||||
return arr1.every((num, index) => num === arr2[index]);
|
||||
}
|
||||
|
||||
// public async set(token: ResumptionToken): Promise<string> {
|
||||
// const uniqueName = await this.generateUniqueName();
|
||||
|
||||
// const serialToken = JSON.stringify(token);
|
||||
// await this.cache.setEx(uniqueName, this.ttl, serialToken);
|
||||
// return uniqueName;
|
||||
// }
|
||||
|
||||
private async generateUniqueName(): Promise<string> {
|
||||
let fc = 0;
|
||||
const uniqueId = dayjs().unix().toString();
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue