Skip to content

Commit

Permalink
Upload prints
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Nov 20, 2024
1 parent 7db66c6 commit da3e318
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
16 changes: 5 additions & 11 deletions Dotnet/WebApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@ private static async Task PrintImageUpload(HttpWebRequest request, IDictionary<s
var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data; boundary=" + boundary;
var requestStream = request.GetRequestStream();
// var requestStream = new MemoryStream();
var imageData = options["imageData"] as string;
var fileToUpload = Convert.FromBase64String(imageData);
var fileToUpload = AppApi.Instance.ResizeImageToFitLimits(Convert.FromBase64String(imageData), 1920, 1080);
const string fileFormKey = "image";
const string fileName = "image";
const string fileMimeType = "image/png";
Expand All @@ -315,6 +314,8 @@ private static async Task PrintImageUpload(HttpWebRequest request, IDictionary<s
var header = string.Format(headerTemplate, boundary, fileFormKey, fileName, fileMimeType, fileSize);
var headerBytes = Encoding.UTF8.GetBytes(header);
await requestStream.WriteAsync(headerBytes);
var newlineBytes = Encoding.UTF8.GetBytes("\r\n");
await requestStream.WriteAsync(newlineBytes);
using (var fileStream = new MemoryStream(fileToUpload))
{
var buffer = new byte[1024];
Expand All @@ -325,10 +326,9 @@ private static async Task PrintImageUpload(HttpWebRequest request, IDictionary<s
}
fileStream.Close();
}
var newlineBytes = Encoding.UTF8.GetBytes("\r\n");
await requestStream.WriteAsync(newlineBytes);
const string textContentType = "text/plain; charset=utf-8";
const string formDataTemplate = "--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\nContent-Type: {2}\r\nContent-Length: {3}\r\n{4}\r\n";
const string formDataTemplate = "--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\nContent-Type: {2}\r\nContent-Length: {3}\r\n\r\n{4}\r\n";
await requestStream.WriteAsync(newlineBytes);
if (options.TryGetValue("postData", out var postDataObject))
{
var jsonPostData = JsonConvert.DeserializeObject<Dictionary<string, string>>(postDataObject.ToString());
Expand All @@ -344,13 +344,7 @@ private static async Task PrintImageUpload(HttpWebRequest request, IDictionary<s
}
var endBytes = Encoding.UTF8.GetBytes("--" + boundary + "--");
await requestStream.WriteAsync(endBytes);
// test file
// var newFileStream = new FileStream(@"D:\WindowsFiles\Desktop\test", FileMode.Create, FileAccess.Write);
// requestStream.WriteTo(newFileStream);
// newFileStream.Close();

requestStream.Close();
// throw new NotImplementedException();
}

#pragma warning disable CS4014
Expand Down
8 changes: 5 additions & 3 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17505,7 +17505,7 @@ speechSynthesis.getVoices();
};

API.$on('PRINT:LIST', function (args) {
$app.printTable = args.json.reverse();
$app.printTable = args.json;
$app.galleryDialogPrintsLoading = false;
});

Expand All @@ -17524,6 +17524,8 @@ speechSynthesis.getVoices();
}
});

$app.data.printUploadNote = '';

$app.methods.onFileChangePrint = function (e) {
var clearFile = function () {
if (document.querySelector('#PrintUploadButton')) {
Expand Down Expand Up @@ -17556,8 +17558,8 @@ speechSynthesis.getVoices();
var date = new Date();
var timestamp = date.toISOString().slice(0, 19);
var params = {
note: 'test print',
worldId: 'wrld_10e5e467-fc65-42ed-8957-f02cace1398c',
note: $app.printUploadNote,
// worldId: '',
timestamp
};
var base64Body = btoa(r.result);
Expand Down
5 changes: 3 additions & 2 deletions html/src/localization/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@
},
"gallery_icons": {
"header": "Manage Photos, Icons, Emojis and Stickers",
"description": "Recommended image size: 1200x900px (4:3)",
"recommended_image_size": "Recommended image size",
"gallery": "Photos",
"icons": "Icons",
"emojis": "Emojis",
Expand All @@ -1284,7 +1284,8 @@
"emoji_animation_fps": "FPS:",
"emoji_animation_frame_count": "Frame Count:",
"emoji_loop_pingpong": "Loop PingPong",
"flipbook_info": "Select a 1024x1024 PNG spritesheet to use as an animated emoji, available frame grid sizes: 4, 16 or 64 (max FPS 64, max frames 64)"
"flipbook_info": "Select a 1024x1024 PNG spritesheet to use as an animated emoji, available frame grid sizes: 4, 16 or 64 (max FPS 64, max frames 64)",
"note": "Note"
},
"change_content_image": {
"avatar": "Change Avatar Image",
Expand Down
23 changes: 19 additions & 4 deletions html/src/mixins/dialogs/currentUser.pug
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ mixin currentUser()

//- dialog: Gallery/VRCPlusIcons
el-dialog.x-dialog(:before-close="beforeDialogClose" @mousedown.native="dialogMouseDown" @mouseup.native="dialogMouseUp" ref="galleryDialog" :visible.sync="galleryDialogVisible" :title="$t('dialog.gallery_icons.header')" width="100%")
span(style="padding-bottom:10px") {{ $t('dialog.gallery_icons.description') }}
br
br
el-tabs(type="card" ref="galleryTabs")
el-tab-pane(v-if="galleryDialogVisible" v-loading="galleryDialogGalleryLoading")
span(slot="label") {{ $t('dialog.gallery_icons.gallery') }}
span(style="color:#909399;font-size:12px;margin-left:5px") {{ galleryTable.length }}/64
input(type="file" accept="image/png,image/jpg,image/jpeg,image/webp,image/bmp,image/gif" @change="onFileChangeGallery" id="GalleryUploadButton" style="display:none")
span {{ $t('dialog.gallery_icons.recommended_image_size') }}: 1200x900px (4:3)
br
br
el-button-group
el-button(type="default" size="small" @click="refreshGalleryTable" icon="el-icon-refresh") {{ $t('dialog.gallery_icons.refresh') }}
el-button(type="default" size="small" @click="displayGalleryUpload" icon="el-icon-upload2" :disabled="!API.currentUser.$isVRCPlus") {{ $t('dialog.gallery_icons.upload') }}
Expand All @@ -84,6 +84,9 @@ mixin currentUser()
span(slot="label") {{ $t('dialog.gallery_icons.icons') }}
span(style="color:#909399;font-size:12px;margin-left:5px") {{ VRCPlusIconsTable.length }}/64
input(type="file" accept="image/png,image/jpg,image/jpeg,image/webp,image/bmp,image/gif" @change="onFileChangeVRCPlusIcon" id="VRCPlusIconUploadButton" style="display:none")
span {{ $t('dialog.gallery_icons.recommended_image_size') }}: 1200x900px (4:3)
br
br
el-button-group
el-button(type="default" size="small" @click="refreshVRCPlusIconsTable" icon="el-icon-refresh") {{ $t('dialog.gallery_icons.refresh') }}
el-button(type="default" size="small" @click="displayVRCPlusIconUpload" icon="el-icon-upload2" :disabled="!API.currentUser.$isVRCPlus") {{ $t('dialog.gallery_icons.upload') }}
Expand All @@ -99,6 +102,9 @@ mixin currentUser()
span(slot="label") {{ $t('dialog.gallery_icons.emojis') }}
span(style="color:#909399;font-size:12px;margin-left:5px") {{ emojiTable.length }}/9
input(type="file" accept="image/png,image/jpg,image/jpeg,image/webp,image/bmp,image/gif" @change="onFileChangeEmoji" id="EmojiUploadButton" style="display:none")
span {{ $t('dialog.gallery_icons.recommended_image_size') }}: 1200x900px (4:3)
br
br
el-button-group(style="margin-right:10px")
el-button(type="default" size="small" @click="refreshEmojiTable" icon="el-icon-refresh") {{ $t('dialog.gallery_icons.refresh') }}
el-button(type="default" size="small" @click="displayEmojiUpload" icon="el-icon-upload2" :disabled="!API.currentUser.$isVRCPlus") {{ $t('dialog.gallery_icons.upload') }}
Expand Down Expand Up @@ -140,6 +146,9 @@ mixin currentUser()
span(slot="label") {{ $t('dialog.gallery_icons.stickers') }}
span(style="color:#909399;font-size:12px;margin-left:5px") {{ stickerTable.length }}/9
input(type="file" accept="image/png,image/jpg,image/jpeg,image/webp,image/bmp,image/gif" @change="onFileChangeSticker" id="StickerUploadButton" style="display:none")
span {{ $t('dialog.gallery_icons.recommended_image_size') }}: 1200x900px (4:3)
br
br
el-button-group
el-button(type="default" size="small" @click="refreshStickerTable" icon="el-icon-refresh") {{ $t('dialog.gallery_icons.refresh') }}
el-button(type="default" size="small" @click="displayStickerUpload" icon="el-icon-upload2" :disabled="!API.currentUser.$isVRCPlus") {{ $t('dialog.gallery_icons.upload') }}
Expand All @@ -154,9 +163,13 @@ mixin currentUser()
span(slot="label") {{ $t('dialog.gallery_icons.prints') }}
span(style="color:#909399;font-size:12px;margin-left:5px") {{ printTable.length }}/64
input(type="file" accept="image/png,image/jpg,image/jpeg,image/webp,image/bmp,image/gif" @change="onFileChangePrint" id="PrintUploadButton" style="display:none")
span {{ $t('dialog.gallery_icons.recommended_image_size') }}: 1920x1080px (16:9)
br
br
el-button-group
el-button(type="default" size="small" @click="refreshPrintTable" icon="el-icon-refresh") {{ $t('dialog.gallery_icons.refresh') }}
//- el-button(type="default" size="small" @click="displayPrintUpload" icon="el-icon-upload2" :disabled="!API.currentUser.$isVRCPlus") {{ $t('dialog.gallery_icons.upload') }}
el-button(type="default" size="small" @click="displayPrintUpload" icon="el-icon-upload2" :disabled="!API.currentUser.$isVRCPlus") {{ $t('dialog.gallery_icons.upload') }}
el-input(type="textarea" v-model="printUploadNote" size="mini" rows="1" resize="none" maxlength="32" style="margin-left:10px;width:300px" :placeholder="$t('dialog.gallery_icons.note')")
br
.x-friend-item(v-for="image in printTable" :key="image.id" style="display:inline-block;margin-top:10px;width:unset;cursor:default")
.vrcplus-icon(style="overflow:hidden" @click="showFullscreenImageDialog(image.files.image)")
Expand All @@ -168,6 +181,8 @@ mixin currentUser()
span(v-else style="display:block") &nbsp;
display-name.x-ellipsis(v-if="image.authorId" :userid="image.authorId" :hint="image.authorName" style="color:#909399;font-family:monospace;display:block")
span(v-else style="font-family:monospace;display:block") &nbsp;
span.x-ellipsis(v-if="image.timestamp" style="color:#909399;font-family:monospace;font-size:11px;display:block") {{ image.timestamp | formatDate('long') }}
span(v-else style="display:block") &nbsp;
div(style="float:right")
el-button(type="default" @click="showFullscreenImageDialog(image.files.image)" size="mini" icon="el-icon-picture-outline" circle)
el-button(type="default" @click="deletePrint(image.id)" size="mini" icon="el-icon-delete" circle style="margin-left:5px")

0 comments on commit da3e318

Please sign in to comment.