2024-10-13 15:25:30 -07:00
|
|
|
import * as v from 'valibot';
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
import { accountSchema } from './account';
|
|
|
|
|
|
|
|
/** @see {@link https://docs.joinmastodon.org/entities/Suggestion} */
|
|
|
|
const suggestionSchema = z.preprocess((suggestion: any) => {
|
|
|
|
/**
|
|
|
|
* Support `/api/v1/suggestions`
|
|
|
|
* @see {@link https://docs.joinmastodon.org/methods/suggestions/#v1}
|
|
|
|
*/
|
2024-09-07 10:58:02 -07:00
|
|
|
if (!suggestion) return null;
|
|
|
|
|
2024-08-28 04:43:23 -07:00
|
|
|
if (suggestion?.acct) return {
|
|
|
|
source: 'staff',
|
2024-09-07 10:58:02 -07:00
|
|
|
sources: ['featured'],
|
2024-08-28 04:43:23 -07:00
|
|
|
account: suggestion,
|
|
|
|
};
|
2024-09-07 10:58:02 -07:00
|
|
|
|
|
|
|
if (!suggestion.sources) {
|
|
|
|
suggestion.sources = [];
|
|
|
|
switch (suggestion.source) {
|
|
|
|
case 'staff':
|
|
|
|
suggestion.sources.push('staff');
|
|
|
|
break;
|
|
|
|
case 'global':
|
|
|
|
suggestion.sources.push('most_interactions');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-28 04:43:23 -07:00
|
|
|
return suggestion;
|
2024-10-13 15:25:30 -07:00
|
|
|
}, v.object({
|
|
|
|
source: v.fallback(v.nullable(v.string()), null),
|
2024-10-14 13:50:34 -07:00
|
|
|
sources: v.fallback(v.array(v.string()), []),
|
2024-08-28 04:43:23 -07:00
|
|
|
account: accountSchema,
|
|
|
|
}));
|
|
|
|
|
2024-10-13 15:25:30 -07:00
|
|
|
type Suggestion = v.InferOutput<typeof suggestionSchema>;
|
2024-08-28 04:43:23 -07:00
|
|
|
|
|
|
|
export { suggestionSchema, type Suggestion };
|