chore: fix ci problem

This commit is contained in:
moonrailgun 2024-06-30 15:56:53 +08:00
parent 85a2a598d7
commit 4d15cccd1b
2 changed files with 66 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import _ from 'lodash';
import { subscribeEventBus } from '../../../ws/shared'; import { subscribeEventBus } from '../../../ws/shared';
import { OpenApiMeta } from 'trpc-openapi'; import { OpenApiMeta } from 'trpc-openapi';
import { OPENAPI_TAG } from '../../../utils/const'; import { OPENAPI_TAG } from '../../../utils/const';
import { serializeJSON } from '../../../utils/json';
export const feedIntegrationRouter = router({ export const feedIntegrationRouter = router({
github: publicProcedure github: publicProcedure
@ -62,7 +63,11 @@ export const feedIntegrationRouter = router({
url, url,
}, },
}); });
subscribeEventBus.emit('onReceiveFeedEvent', workspaceId, event); subscribeEventBus.emit(
'onReceiveFeedEvent',
workspaceId,
serializeJSON(event)
);
return 'ok'; return 'ok';
} else if (eventType === 'star') { } else if (eventType === 'star') {
@ -84,7 +89,11 @@ export const feedIntegrationRouter = router({
url, url,
}, },
}); });
subscribeEventBus.emit('onReceiveFeedEvent', workspaceId, event); subscribeEventBus.emit(
'onReceiveFeedEvent',
workspaceId,
serializeJSON(event)
);
return 'ok'; return 'ok';
} else if (eventType === 'issues') { } else if (eventType === 'issues') {
@ -120,7 +129,11 @@ export const feedIntegrationRouter = router({
url, url,
}, },
}); });
subscribeEventBus.emit('onReceiveFeedEvent', workspaceId, event); subscribeEventBus.emit(
'onReceiveFeedEvent',
workspaceId,
serializeJSON(event)
);
return 'ok'; return 'ok';
} }

50
src/server/utils/json.ts Normal file
View File

@ -0,0 +1,50 @@
/**
* serialize object
* make data easy to transfer
*/
export function serializeJSON<T extends {}>(input: T) {
return serializeDate(input);
}
type ConvertDateToString<T> = T extends Date
? string
: T extends Date | null
? string | null
: T extends Date | undefined
? string | undefined
: T extends Date | null | undefined
? string | null | undefined
: T;
export type DateToString<T> = {
[P in keyof T]: T[P] extends Date | null | undefined
? ConvertDateToString<T[P]>
: DateToString<T[P]>;
};
function serializeDate<T extends {}>(obj: T): DateToString<T> {
function stripDates(_obj: unknown): any {
if (!_obj || typeof _obj !== 'object') {
return _obj;
}
if (_obj instanceof Date) {
return _obj.toISOString();
}
if (Array.isArray(_obj)) {
return _obj.map(stripDates);
}
return Object.keys(_obj).reduce(
(acc, key) => {
const value = (_obj as any)[key];
acc[key] = stripDates(value); // Recursive to handle nested objects
return acc;
},
{} as { [key: string]: any }
);
}
return stripDates(obj);
}