@@ -7,11 +7,9 @@ import {
77 HttpServerRequest ,
88 HttpServerResponse ,
99} from '@effect/platform'
10- import { Array , Config , Context , Data , Effect , Exit , Match , Option , ParseResult , Schema , pipe } from 'effect'
10+ import { Array , Config , Context , Data , Effect , Match , Option , Schema , pipe } from 'effect'
1111import { StatusCodes } from 'http-status-codes'
12- import { createHash } from 'node:crypto'
1312import slackifyMarkdown from 'slackify-markdown'
14- import * as BullMq from './BullMq.js'
1513import * as CoarNotify from './CoarNotify.js'
1614import * as Doi from './Doi.js'
1715import * as LanguageCode from './LanguageCode.js'
@@ -194,50 +192,21 @@ export const Router = HttpRouter.empty.pipe(
194192 HttpRouter . post (
195193 '/inbox' ,
196194 Effect . gen ( function * ( ) {
197- const requestReview = yield * HttpServerRequest . schemaBodyJson ( CoarNotify . RequestReviewSchema )
198- const encoded = yield * Schema . encode ( CoarNotify . RequestReviewSchema ) ( requestReview )
195+ const prereviewUrl = yield * Prereview . PrereviewUrl
199196
200- yield * pipe (
201- BullMq . add ( 'coar-notify' , 'request-review' , encoded , {
202- jobId : BullMq . JobId ( md5 ( requestReview . object [ 'ietf:cite-as' ] ) ) ,
203- } ) ,
204- Effect . acquireRelease ( ( jobId , exit ) =>
205- Exit . matchEffect ( exit , {
206- onFailure : ( ) =>
207- Effect . catchAll ( BullMq . remove ( 'coar-notify' , jobId ) , error =>
208- Effect . annotateLogs ( Effect . logError ( 'Unable to remove job' ) , {
209- queue : 'coar-notify' ,
210- jobId,
211- message : error . message ,
212- } ) ,
213- ) ,
214- onSuccess : ( ) => Effect . void ,
215- } ) ,
216- ) ,
217- )
218-
219- return yield * HttpServerResponse . empty ( { status : StatusCodes . CREATED } )
220- } ) . pipe (
221- Effect . catchTags ( {
222- BullMqError : error =>
223- Effect . gen ( function * ( ) {
224- yield * Effect . logError ( 'Unable to write job to BullMQ' ) . pipe (
225- Effect . annotateLogs ( { message : error . message } ) ,
226- )
197+ if ( prereviewUrl . href === 'https://prereview.org/' ) {
198+ return yield * HttpServerResponse . json ( { app : 'prereview' } , { contentType : 'application/vnd.fly.replay+json' } )
199+ }
227200
228- return HttpServerResponse . empty ( { status : StatusCodes . SERVICE_UNAVAILABLE } )
229- } ) ,
230- ParseError : error =>
231- Effect . gen ( function * ( ) {
232- yield * Effect . logInfo ( 'Invalid request' ) . pipe (
233- Effect . annotateLogs ( { message : ParseResult . TreeFormatter . formatErrorSync ( error ) } ) ,
234- )
201+ if ( prereviewUrl . href === 'https://sandbox.prereview.org/' ) {
202+ return yield * HttpServerResponse . json (
203+ { app : 'prereview-sandbox' } ,
204+ { contentType : 'application/vnd.fly.replay+json' } ,
205+ )
206+ }
235207
236- return HttpServerResponse . empty ( { status : StatusCodes . BAD_REQUEST } )
237- } ) ,
238- RequestError : ( ) => HttpServerResponse . empty ( { status : StatusCodes . BAD_REQUEST } ) ,
239- } ) ,
240- ) ,
208+ return yield * HttpServerResponse . empty ( { status : StatusCodes . SERVICE_UNAVAILABLE } )
209+ } ) ,
241210 ) ,
242211 Effect . catchTag ( 'RouteNotFound' , ( ) => HttpServerResponse . empty ( { status : StatusCodes . NOT_FOUND } ) ) ,
243212)
@@ -345,5 +314,3 @@ const notifyScietyCoarInbox = (prereviewUrl: URL) =>
345314
346315 yield * Effect . annotateLogs ( Effect . logDebug ( 'Should notify Sciety' ) , 'message' , message )
347316 } )
348-
349- const md5 = ( content : string ) => createHash ( 'md5' ) . update ( content ) . digest ( 'hex' )
0 commit comments