Fix OpenAPI workspace query drift (#26609)
This commit is contained in:
@@ -34,6 +34,7 @@ export const messageHandlers = HttpApiBuilder.group(InstanceHttpApi, "v2.message
|
||||
return handlers.handle(
|
||||
"messages",
|
||||
Effect.fn(function* (ctx) {
|
||||
if (ctx.query.cursor && ctx.query.order !== undefined) return yield* new HttpApiError.BadRequest({})
|
||||
const decoded = yield* Effect.try({
|
||||
try: () => (ctx.query.cursor ? cursor.decode(ctx.query.cursor) : undefined),
|
||||
catch: () => new HttpApiError.BadRequest({}),
|
||||
|
||||
@@ -22,6 +22,31 @@ type SessionCursor = typeof SessionCursor.Type
|
||||
|
||||
const decodeCursor = Schema.decodeUnknownSync(SessionCursor)
|
||||
|
||||
function hasCursorFilter(query: {
|
||||
readonly order?: unknown
|
||||
readonly path?: unknown
|
||||
readonly roots?: unknown
|
||||
readonly start?: unknown
|
||||
readonly search?: unknown
|
||||
}) {
|
||||
return (
|
||||
query.order !== undefined ||
|
||||
query.path !== undefined ||
|
||||
query.roots !== undefined ||
|
||||
query.start !== undefined ||
|
||||
query.search !== undefined
|
||||
)
|
||||
}
|
||||
|
||||
function hasCursorRoutingMismatch(
|
||||
query: { readonly directory?: string; readonly workspace?: string },
|
||||
decoded: SessionCursor | undefined,
|
||||
) {
|
||||
if (!decoded) return false
|
||||
if (query.directory !== undefined && query.directory !== decoded.directory) return true
|
||||
return query.workspace !== undefined && query.workspace !== decoded.workspaceID
|
||||
}
|
||||
|
||||
const sessionCursor = {
|
||||
encode(
|
||||
session: SessionV2.Info,
|
||||
@@ -46,10 +71,12 @@ export const sessionHandlers = HttpApiBuilder.group(InstanceHttpApi, "v2.session
|
||||
.handle(
|
||||
"sessions",
|
||||
Effect.fn(function* (ctx) {
|
||||
if (ctx.query.cursor && hasCursorFilter(ctx.query)) return yield* new HttpApiError.BadRequest({})
|
||||
const decoded = yield* Effect.try({
|
||||
try: () => (ctx.query.cursor ? sessionCursor.decode(ctx.query.cursor) : undefined),
|
||||
catch: () => new HttpApiError.BadRequest({}),
|
||||
})
|
||||
if (hasCursorRoutingMismatch(ctx.query, decoded)) return yield* new HttpApiError.BadRequest({})
|
||||
const order = decoded?.order ?? ctx.query.order ?? "desc"
|
||||
const filters = decoded ?? {
|
||||
directory: ctx.query.directory,
|
||||
|
||||
Reference in New Issue
Block a user