fix(core): provide photoengine (#6574)

This commit is contained in:
pengx17 2024-04-17 13:27:10 +00:00
parent 03a7f9939e
commit f9f0490190
No known key found for this signature in database
GPG Key ID: 23F23D9E8B3971ED

View File

@ -1,4 +1,5 @@
import { openSettingModalAtom } from '@affine/core/atoms';
import { getBaseUrl } from '@affine/graphql';
import { assertExists } from '@blocksuite/global/utils';
import { AIProvider } from '@blocksuite/presets';
import { getCurrentStore } from '@toeverything/infra';
@ -266,6 +267,29 @@ export function setupAIProvider() {
});
});
AIProvider.provide('photoEngine', {
async searchImages(options): Promise<string[]> {
const url = new URL(getBaseUrl() + '/api/copilot/unsplash/photos');
url.searchParams.set('query', options.query);
const result: {
results: {
urls: {
regular: string;
};
}[];
} = await fetch(url.toString()).then(res => res.json());
return result.results.map(r => {
const url = new URL(r.urls.regular);
url.searchParams.set('fit', 'crop');
url.searchParams.set('crop', 'edges');
url.searchParams.set('dpr', (window.devicePixelRatio ?? 2).toString());
url.searchParams.set('w', `${options.width}`);
url.searchParams.set('h', `${options.height}`);
return url.toString();
});
},
});
AIProvider.slots.requestUpgradePlan.on(() => {
getCurrentStore().set(openSettingModalAtom, {
activeTab: 'billing',