This commit is contained in:
syuilo 2025-05-13 17:44:59 +09:00
parent edeeca8b5f
commit 0397a5046d
3 changed files with 105 additions and 62 deletions

View File

@ -71,8 +71,6 @@ const ok = async () => {
}); });
}); });
os.promiseDialog(promise);
const f = await promise; const f = await promise;
emit('ok', f); emit('ok', f);

View File

@ -67,33 +67,32 @@ watch(description, () => {
}); });
}); });
function setAvatar(ev) { async function setAvatar(ev) {
os.chooseFileFromPc({ multiple: false }).then(async (files) => { const files = await os.chooseFileFromPc({ multiple: false });
const file = files[0]; const file = files[0];
let originalOrCropped = file; let originalOrCropped = file;
const { canceled } = await os.confirm({ const { canceled } = await os.confirm({
type: 'question', type: 'question',
text: i18n.ts.cropImageAsk, text: i18n.ts.cropImageAsk,
okText: i18n.ts.cropYes, okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo, cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.cropImageFile(file, {
aspectRatio: 1,
});
}
const driveFile = (await os.launchUploader([originalOrCropped], {}))[0];
const i = await os.apiWithDialog('i/update', {
avatarId: driveFile.id,
});
$i.avatarId = i.avatarId;
$i.avatarUrl = i.avatarUrl;
}); });
if (!canceled) {
originalOrCropped = await os.cropImageFile(file, {
aspectRatio: 1,
});
}
const driveFile = (await os.launchUploader([originalOrCropped], {}))[0];
const i = await os.apiWithDialog('i/update', {
avatarId: driveFile.id,
});
$i.avatarId = i.avatarId;
$i.avatarUrl = i.avatarUrl;
} }
</script> </script>

View File

@ -257,54 +257,100 @@ function save() {
} }
function changeAvatar(ev) { function changeAvatar(ev) {
selectFile(ev.currentTarget ?? ev.target, i18n.ts.avatar).then(async (file) => { async function done(driveFile) {
let originalOrCropped = file;
const { canceled } = await os.confirm({
type: 'question',
text: i18n.ts.cropImageAsk,
okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.createCroppedImageDriveFileFromImageDriveFile(file, {
aspectRatio: 1,
});
}
const i = await os.apiWithDialog('i/update', { const i = await os.apiWithDialog('i/update', {
avatarId: originalOrCropped.id, avatarId: driveFile.id,
}); });
$i.avatarId = i.avatarId; $i.avatarId = i.avatarId;
$i.avatarUrl = i.avatarUrl; $i.avatarUrl = i.avatarUrl;
claimAchievement('profileFilled'); claimAchievement('profileFilled');
}); }
os.popupMenu([{
text: i18n.ts.avatar,
type: 'label',
}, {
text: i18n.ts.upload,
icon: 'ti ti-upload',
action: async () => {
const files = await os.chooseFileFromPc({ multiple: false });
const file = files[0];
let originalOrCropped = file;
const { canceled } = await os.confirm({
type: 'question',
text: i18n.ts.cropImageAsk,
okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.cropImageFile(file, {
aspectRatio: 1,
});
}
const driveFile = (await os.launchUploader([originalOrCropped], {}))[0];
done(driveFile);
},
}, {
text: i18n.ts.fromDrive,
icon: 'ti ti-cloud',
action: () => {
os.selectDriveFile(false).then(files => {
done(files[0]);
});
},
}], ev.currentTarget ?? ev.target);
} }
function changeBanner(ev) { function changeBanner(ev) {
selectFile(ev.currentTarget ?? ev.target, i18n.ts.banner).then(async (file) => { async function done(driveFile) {
let originalOrCropped = file;
const { canceled } = await os.confirm({
type: 'question',
text: i18n.ts.cropImageAsk,
okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.createCroppedImageDriveFileFromImageDriveFile(file, {
aspectRatio: 2,
});
}
const i = await os.apiWithDialog('i/update', { const i = await os.apiWithDialog('i/update', {
bannerId: originalOrCropped.id, bannerId: driveFile.id,
}); });
$i.bannerId = i.bannerId; $i.bannerId = i.bannerId;
$i.bannerUrl = i.bannerUrl; $i.bannerUrl = i.bannerUrl;
}); }
os.popupMenu([{
text: i18n.ts.banner,
type: 'label',
}, {
text: i18n.ts.upload,
icon: 'ti ti-upload',
action: async () => {
const files = await os.chooseFileFromPc({ multiple: false });
const file = files[0];
let originalOrCropped = file;
const { canceled } = await os.confirm({
type: 'question',
text: i18n.ts.cropImageAsk,
okText: i18n.ts.cropYes,
cancelText: i18n.ts.cropNo,
});
if (!canceled) {
originalOrCropped = await os.cropImageFile(file, {
aspectRatio: 2,
});
}
const driveFile = (await os.launchUploader([originalOrCropped], {}))[0];
done(driveFile);
},
}, {
text: i18n.ts.fromDrive,
icon: 'ti ti-cloud',
action: () => {
os.selectDriveFile(false).then(files => {
done(files[0]);
});
},
}], ev.currentTarget ?? ev.target);
} }
const headerActions = computed(() => []); const headerActions = computed(() => []);