mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into pin-styles
This commit is contained in:
11
public/global.d.ts
vendored
11
public/global.d.ts
vendored
@@ -55,4 +55,15 @@ declare global {
|
|||||||
* @param provider Translation provider
|
* @param provider Translation provider
|
||||||
*/
|
*/
|
||||||
async function translate(text: string, lang: string, provider: string = null): Promise<string>;
|
async function translate(text: string, lang: string, provider: string = null): Promise<string>;
|
||||||
|
|
||||||
|
interface ConvertVideoArgs {
|
||||||
|
buffer: Uint8Array;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a video file to an animated WebP format using FFmpeg.
|
||||||
|
* @param args - The arguments for the conversion function.
|
||||||
|
*/
|
||||||
|
function convertVideoToAnimatedWebp(args: ConvertVideoArgs): Promise<Uint8Array>;
|
||||||
}
|
}
|
||||||
|
@@ -4968,7 +4968,7 @@
|
|||||||
<div id="bg_menu_content" class="bg_list">
|
<div id="bg_menu_content" class="bg_list">
|
||||||
<form id="form_bg_download" class="bg_example no-border no-shadow" action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
<form id="form_bg_download" class="bg_example no-border no-shadow" action="javascript:void(null);" method="post" enctype="multipart/form-data">
|
||||||
<label class="input-file">
|
<label class="input-file">
|
||||||
<input type="file" id="add_bg_button" name="avatar" accept="image/png, image/jpeg, image/jpg, image/gif, image/bmp">
|
<input type="file" id="add_bg_button" name="avatar" accept="image/*, video/*">
|
||||||
<div class="bg_example no-border no-shadow add_bg_but" style="background-image: url('/img/addbg3.png');"></div>
|
<div class="bg_example no-border no-shadow add_bg_but" style="background-image: url('/img/addbg3.png');"></div>
|
||||||
</label>
|
</label>
|
||||||
</form>
|
</form>
|
||||||
|
@@ -9154,7 +9154,7 @@ function formatSwipeCounter(current, total) {
|
|||||||
* @param {string} [params.source] The source of the swipe event.
|
* @param {string} [params.source] The source of the swipe event.
|
||||||
* @param {boolean} [params.repeated] Is the swipe event repeated.
|
* @param {boolean} [params.repeated] Is the swipe event repeated.
|
||||||
*/
|
*/
|
||||||
function swipe_left(_event, { source, repeated } = {}) {
|
export function swipe_left(_event, { source, repeated } = {}) {
|
||||||
if (chat.length - 1 === Number(this_edit_mes_id)) {
|
if (chat.length - 1 === Number(this_edit_mes_id)) {
|
||||||
closeMessageEditor();
|
closeMessageEditor();
|
||||||
}
|
}
|
||||||
@@ -9302,7 +9302,7 @@ function swipe_left(_event, { source, repeated } = {}) {
|
|||||||
* @param {string} [params.source] The source of the swipe event.
|
* @param {string} [params.source] The source of the swipe event.
|
||||||
* @param {boolean} [params.repeated] Is the swipe event repeated.
|
* @param {boolean} [params.repeated] Is the swipe event repeated.
|
||||||
*/
|
*/
|
||||||
function swipe_right(_event, { source, repeated } = {}) {
|
export function swipe_right(_event, { source, repeated } = {}) {
|
||||||
if (chat.length - 1 === Number(this_edit_mes_id)) {
|
if (chat.length - 1 === Number(this_edit_mes_id)) {
|
||||||
closeMessageEditor();
|
closeMessageEditor();
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { Fuse } from '../lib.js';
|
import { Fuse } from '../lib.js';
|
||||||
|
|
||||||
import { callPopup, chat_metadata, eventSource, event_types, generateQuietPrompt, getCurrentChatId, getRequestHeaders, getThumbnailUrl, saveSettingsDebounced } from '../script.js';
|
import { callPopup, chat_metadata, eventSource, event_types, generateQuietPrompt, getCurrentChatId, getRequestHeaders, getThumbnailUrl, saveSettingsDebounced } from '../script.js';
|
||||||
import { saveMetadataDebounced } from './extensions.js';
|
import { openThirdPartyExtensionMenu, saveMetadataDebounced } from './extensions.js';
|
||||||
import { SlashCommand } from './slash-commands/SlashCommand.js';
|
import { SlashCommand } from './slash-commands/SlashCommand.js';
|
||||||
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
|
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
|
||||||
import { flashHighlight, stringFormat } from './utils.js';
|
import { flashHighlight, stringFormat } from './utils.js';
|
||||||
@@ -78,7 +78,7 @@ function getChatBackgroundsList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getBackgroundPath(fileUrl) {
|
function getBackgroundPath(fileUrl) {
|
||||||
return `backgrounds/${fileUrl}`;
|
return `backgrounds/${encodeURIComponent(fileUrl)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function highlightLockedBackground() {
|
function highlightLockedBackground() {
|
||||||
@@ -218,7 +218,7 @@ async function onCopyToSystemBackgroundClick(e) {
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.set('avatar', file);
|
formData.set('avatar', file);
|
||||||
|
|
||||||
uploadBackground(formData);
|
await uploadBackground(formData);
|
||||||
|
|
||||||
const list = chat_metadata[LIST_METADATA_KEY] || [];
|
const list = chat_metadata[LIST_METADATA_KEY] || [];
|
||||||
const index = list.indexOf(bgNames.oldBg);
|
const index = list.indexOf(bgNames.oldBg);
|
||||||
@@ -439,7 +439,7 @@ async function delBackground(bg) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function onBackgroundUploadSelected() {
|
async function onBackgroundUploadSelected() {
|
||||||
const form = $('#form_bg_download').get(0);
|
const form = $('#form_bg_download').get(0);
|
||||||
|
|
||||||
if (!(form instanceof HTMLFormElement)) {
|
if (!(form instanceof HTMLFormElement)) {
|
||||||
@@ -448,34 +448,82 @@ function onBackgroundUploadSelected() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
uploadBackground(formData);
|
await convertFileIfVideo(formData);
|
||||||
|
await uploadBackground(formData);
|
||||||
form.reset();
|
form.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a video file to an animated webp format if the file is a video.
|
||||||
|
* @param {FormData} formData
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async function convertFileIfVideo(formData) {
|
||||||
|
const file = formData.get('avatar');
|
||||||
|
if (!(file instanceof File)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!file.type.startsWith('video/')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof globalThis.convertVideoToAnimatedWebp !== 'function') {
|
||||||
|
toastr.warning(t`Click here to install the Video Background Loader extension`, t`Video background uploads require a downloadable add-on`, {
|
||||||
|
timeOut: 0,
|
||||||
|
extendedTimeOut: 0,
|
||||||
|
onclick: () => openThirdPartyExtensionMenu('https://github.com/SillyTavern/Extension-VideoBackgroundLoader'),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let toastMessage = jQuery();
|
||||||
|
try {
|
||||||
|
toastMessage = toastr.info(t`Preparing video for upload. This may take several minutes.`, t`Please wait`, { timeOut: 0, extendedTimeOut: 0 });
|
||||||
|
const sourceBuffer = await file.arrayBuffer();
|
||||||
|
const convertedBuffer = await globalThis.convertVideoToAnimatedWebp({ buffer: new Uint8Array(sourceBuffer), name: file.name });
|
||||||
|
const convertedFileName = file.name.replace(/\.[^/.]+$/, '.webp');
|
||||||
|
const convertedFile = new File([convertedBuffer], convertedFileName, { type: 'image/webp' });
|
||||||
|
formData.set('avatar', convertedFile);
|
||||||
|
toastMessage.remove();
|
||||||
|
} catch (error) {
|
||||||
|
formData.delete('avatar');
|
||||||
|
toastMessage.remove();
|
||||||
|
console.error('Error converting video to animated webp:', error);
|
||||||
|
toastr.error(t`Error converting video to animated webp`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uploads a background to the server
|
* Uploads a background to the server
|
||||||
* @param {FormData} formData
|
* @param {FormData} formData
|
||||||
*/
|
*/
|
||||||
function uploadBackground(formData) {
|
async function uploadBackground(formData) {
|
||||||
jQuery.ajax({
|
try {
|
||||||
type: 'POST',
|
if (!formData.has('avatar')) {
|
||||||
url: '/api/backgrounds/upload',
|
console.log('No file provided. Background upload cancelled.');
|
||||||
data: formData,
|
return;
|
||||||
beforeSend: function () {
|
}
|
||||||
},
|
|
||||||
cache: false,
|
const headers = getRequestHeaders();
|
||||||
contentType: false,
|
delete headers['Content-Type'];
|
||||||
processData: false,
|
|
||||||
success: async function (bg) {
|
const response = await fetch('/api/backgrounds/upload', {
|
||||||
setBackground(bg, generateUrlParameter(bg, false));
|
method: 'POST',
|
||||||
await getBackgrounds();
|
headers: headers,
|
||||||
highlightNewBackground(bg);
|
body: formData,
|
||||||
},
|
cache: 'no-cache',
|
||||||
error: function (jqXHR, exception) {
|
});
|
||||||
console.log(exception);
|
|
||||||
console.log(jqXHR);
|
if (!response.ok) {
|
||||||
},
|
throw new Error('Failed to upload background');
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const bg = await response.text();
|
||||||
|
setBackground(bg, generateUrlParameter(bg, false));
|
||||||
|
await getBackgrounds();
|
||||||
|
highlightNewBackground(bg);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error uploading background:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -50,6 +50,8 @@ import {
|
|||||||
unshallowCharacter,
|
unshallowCharacter,
|
||||||
deleteLastMessage,
|
deleteLastMessage,
|
||||||
getCharacterCardFields,
|
getCharacterCardFields,
|
||||||
|
swipe_right,
|
||||||
|
swipe_left,
|
||||||
} from '../script.js';
|
} from '../script.js';
|
||||||
import {
|
import {
|
||||||
extension_settings,
|
extension_settings,
|
||||||
@@ -196,6 +198,7 @@ export function getContext() {
|
|||||||
humanizedDateTime,
|
humanizedDateTime,
|
||||||
updateMessageBlock,
|
updateMessageBlock,
|
||||||
appendMediaToMessage,
|
appendMediaToMessage,
|
||||||
|
swipe: { left: swipe_left, right: swipe_right },
|
||||||
variables: {
|
variables: {
|
||||||
local: {
|
local: {
|
||||||
get: getLocalVariable,
|
get: getLocalVariable,
|
||||||
|
Reference in New Issue
Block a user