Skip to content

Commit 3111e67

Browse files
committed
chore: use base64 as demo & fix style
1 parent 893951c commit 3111e67

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/ai-native/src/browser/components/components.module.less

+2
Original file line numberDiff line numberDiff line change
@@ -635,12 +635,14 @@
635635
display: flex;
636636
justify-content: center;
637637
align-items: center;
638+
background-color: var(--badge-background);
638639
&:hover {
639640
cursor: pointer;
640641
transform: scale(1.2);
641642
}
642643
:global(.codicon) {
643644
font-size: 12px;
645+
color: var(--badge-foreground);
644646
}
645647
}
646648
}

packages/startup/entry/sample-modules/ai-native/ai-native.contribution.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,30 @@ export class AINativeContribution implements AINativeCoreContribution {
512512

513513
registerImageUploadProvider(registry: IImageUploadProviderRegistry): void {
514514
registry.registerImageUploadProvider({
515-
imageUpload: async (file) =>
516-
'https://img.alicdn.com/imgextra/i1/O1CN01IhPyCU1JeK3xDkJVv_!!6000000001053-2-tps-180-180.png',
515+
imageUpload: async (file) => {
516+
const base64 = await imageToBase64(file);
517+
return new URL(base64);
518+
},
517519
});
518520
}
519521
}
522+
523+
const MAX_IMAGE_SIZE = 3 * 1024 * 1024;
524+
525+
const imageToBase64 = (file: File) =>
526+
new Promise<string>((resolve, reject) => {
527+
if (file.size > MAX_IMAGE_SIZE) {
528+
reject(new Error('Image size exceeds 3MB limit'));
529+
return;
530+
}
531+
532+
const reader = new FileReader();
533+
reader.onload = () => {
534+
const base64String = reader.result as string;
535+
resolve(base64String);
536+
};
537+
reader.onerror = () => {
538+
reject(new Error('Failed to convert image to base64'));
539+
};
540+
reader.readAsDataURL(file);
541+
});

0 commit comments

Comments
 (0)