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
|
@ -314,9 +314,11 @@ router
|
|||
.as('dataset.deleteUpdate')
|
||||
.use([middleware.auth(), middleware.can(['dataset-delete'])]);
|
||||
router.get('/person', [PersonController, 'index']).as('person.index').use([middleware.auth()]);
|
||||
router.get('/dataset/categorize', ({ inertia }: HttpContext) => {
|
||||
return inertia.render('Submitter/Dataset/Category');
|
||||
});
|
||||
router
|
||||
.get('/dataset/:id/categorize', [DatasetController, 'categorize'])
|
||||
.as('dataset.categorize')
|
||||
.where('id', router.matchers.number())
|
||||
.use([middleware.auth(), middleware.can(['dataset-edit'])]);
|
||||
})
|
||||
.prefix('submitter');
|
||||
|
||||
|
|
|
@ -6,10 +6,12 @@ import HomeController from '#controllers/Http/Api/HomeController';
|
|||
import FileController from '#controllers/Http/Api/FileController';
|
||||
import AvatarController from '#controllers/Http/Api/AvatarController';
|
||||
import UserController from '#controllers/Http/Api/UserController';
|
||||
import CollectionsController from '#controllers/Http/Api/collections_controller';
|
||||
import { middleware } from '../kernel.js';
|
||||
// API
|
||||
router
|
||||
.group(() => {
|
||||
router.get('clients', [UserController, 'getSubmitters']).as('client.index');
|
||||
router.get('authors', [AuthorsController, 'index']).as('author.index');
|
||||
router.get('datasets', [DatasetController, 'index']).as('dataset.index');
|
||||
router.get('persons', [AuthorsController, 'persons']).as('author.persons');
|
||||
|
@ -32,6 +34,8 @@ router
|
|||
.post('/twofactor_backupcodes/settings/create', [UserController, 'createCodes'])
|
||||
.as('apps.twofactor_backupcodes.create')
|
||||
.use(middleware.auth());
|
||||
|
||||
router.get('collections/:id', [CollectionsController, 'show']).as('collection.show')
|
||||
})
|
||||
// .namespace('App/Controllers/Http/Api')
|
||||
.prefix('api');
|
||||
|
|
|
@ -19,12 +19,63 @@ async function checkDoiExists(doi: string): Promise<boolean> {
|
|||
}
|
||||
|
||||
// Function to check if ISBN exists using the Open Library API
|
||||
// async function checkIsbnExists(isbn: string): Promise<boolean> {
|
||||
// try {
|
||||
// const response = await axios.get(`https://isbnsearch.org/isbn/${isbn}`);
|
||||
// return response.status === 200 && response.data.includes('ISBN'); // Check if response contains ISBN information
|
||||
// } catch (error) {
|
||||
// return false; // If request fails, ISBN does not exist
|
||||
// }
|
||||
// }
|
||||
|
||||
async function checkIsbnExists(isbn: string): Promise<boolean> {
|
||||
// Try Open Library first
|
||||
try {
|
||||
const response = await axios.get(`https://isbnsearch.org/isbn/${isbn}`);
|
||||
return response.status === 200 && response.data.includes('ISBN'); // Check if response contains ISBN information
|
||||
const response = await axios.get(`https://openlibrary.org/api/books?bibkeys=ISBN:${isbn}&format=json&jscmd=data`);
|
||||
const data = response.data;
|
||||
if (Object.keys(data).length > 0) {
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
return false; // If request fails, ISBN does not exist
|
||||
// If an error occurs, continue to the next API
|
||||
}
|
||||
|
||||
// Fallback to Google Books API
|
||||
try {
|
||||
const response = await axios.get(`https://www.googleapis.com/books/v1/volumes?q=isbn:${isbn}`);
|
||||
const data = response.data;
|
||||
if (data.totalItems > 0) {
|
||||
return true;
|
||||
}
|
||||
} catch (error) {
|
||||
// If an error occurs, continue to the next API
|
||||
}
|
||||
|
||||
// Lastly use the Koha library by scraping HTML
|
||||
try {
|
||||
const response = await axios.get(`https://bibliothek.geosphere.at/cgi-bin/koha/opac-search.pl?idx=nb&q=${isbn}`);
|
||||
const html = response.data;
|
||||
// Check if zero results are explicitly indicated (German or English)
|
||||
if (html.includes('Keine Treffer gefunden!') || html.includes('Your search returned 0 results')) {
|
||||
return false;
|
||||
}
|
||||
// Try to extract the count from German message
|
||||
let match = html.match(/Ihre Suche erzielte\s*(\d+)\s*Treffer/);
|
||||
|
||||
// If not found, try the English equivalent
|
||||
if (!match) {
|
||||
match = html.match(/Your search returned\s*(\d+)\s*results/);
|
||||
}
|
||||
|
||||
if (match && match[1]) {
|
||||
const count = parseInt(match[1], 10);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
// Fallback: if no match is found, return false
|
||||
return false;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,10 +93,10 @@ async function validateReference(value: unknown, options: Options, field: FieldC
|
|||
try {
|
||||
const exists = await checkDoiExists(value);
|
||||
if (!exists) {
|
||||
field.report('The {{ field }} must be an existing DOI', 'validateReference', field);
|
||||
field.report('The {{ field }} must be an existing URL', 'validateReference', field);
|
||||
}
|
||||
} catch (error) {
|
||||
field.report('Error checking DOI existence: ' + error.message, 'validateReference', field);
|
||||
field.report('Error checking URL existence: ' + error.message, 'validateReference', field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue