Skip to content

Commit

Permalink
Merge pull request #520 from impresso/develop
Browse files Browse the repository at this point in the history
Release v3.1.2
  • Loading branch information
theorm authored Feb 20, 2025
2 parents c674d68 + 4094cf3 commit f246de9
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/services/images/images-v1.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { HookContext } from '@feathersjs/feathers'
import { ImpressoApplication } from '../../types'
import { Image } from '../../models/generated/schemas'
import { protobuf } from 'impresso-jscommons'
import { BadRequest } from '@feathersjs/errors'

// const { authenticate } = require('@feathersjs/authentication').hooks;
const {
Expand Down Expand Up @@ -63,7 +65,6 @@ const updateIiifUrls = (context: HookContext<ImpressoApplication>) => {
})
})
})
console.log(context.result.data)
}
}

Expand Down Expand Up @@ -111,17 +112,36 @@ const convertItemToNewImageFormat = (context: HookContext<ImpressoApplication>)
context.result = newResult
}

const deserializeFilters = (serializedFilters: string) => {
if (serializedFilters == null) return []
try {
return protobuf.searchQuery.deserialize(serializedFilters).filters || []
} catch (error) {
throw new BadRequest(`Could not deserialize filters: ${(error as Error).message}`)
}
}

// parse filters
const parseFiltersHook = (context: HookContext<ImpressoApplication>) => {
const { filters } = context.params?.query ?? {}
context.params.query.filters = deserializeFilters(filters)
console.log('ooo', context.params.query.filters)
}

const parseQ = (context: HookContext<ImpressoApplication>) => {
if (context?.params?.query?.term) {
context.params.query.q = context.params.query.term
}
}

export default {
before: {
all: [
// authenticate('jwt')
],
find: [
(context: HookContext<ImpressoApplication>) => {
if (context?.params?.query?.term) {
context.params.query.q = context.params.query.term
}
},
parseFiltersHook,
parseQ,
validate({
order_by: utils.orderBy({
values: {
Expand Down

0 comments on commit f246de9

Please sign in to comment.