mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-18 22:33:50 +02:00
Fix emoji and sticker saving
This commit is contained in:
@@ -1,4 +1,23 @@
|
||||
const inventoryReq = {
|
||||
/**
|
||||
* @param {{ inventoryId: string, userId: string }} params
|
||||
* @returns {Promise<{json: any, params}>}
|
||||
*/
|
||||
getUserInventoryItem(params) {
|
||||
return window.API.call(
|
||||
`user/${params.userId}/inventory/${params.inventoryId}`,
|
||||
{
|
||||
method: 'GET'
|
||||
}
|
||||
).then((json) => {
|
||||
const args = {
|
||||
json,
|
||||
params
|
||||
};
|
||||
return args;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {{ inventoryId: string }} params
|
||||
* @returns {Promise<{json: any, params}>}
|
||||
|
||||
43
src/app.js
43
src/app.js
@@ -10919,6 +10919,7 @@ console.log(`isLinux: ${LINUX}`);
|
||||
|
||||
$app.methods.trySaveStickerToFile = async function (
|
||||
displayName,
|
||||
userId,
|
||||
inventoryId
|
||||
) {
|
||||
if (this.instanceStickersCache.includes(inventoryId)) {
|
||||
@@ -10928,10 +10929,19 @@ console.log(`isLinux: ${LINUX}`);
|
||||
if (this.instanceStickersCache.size > 100) {
|
||||
this.instanceStickersCache.shift();
|
||||
}
|
||||
var args = await inventoryRequest.getInventoryItem({
|
||||
inventoryId
|
||||
var args = await inventoryRequest.getUserInventoryItem({
|
||||
inventoryId,
|
||||
userId
|
||||
});
|
||||
|
||||
if (
|
||||
args.json.itemType !== 'sticker' ||
|
||||
!args.json.flags.includes('ugc')
|
||||
) {
|
||||
// Not a sticker or ugc, skipping
|
||||
return;
|
||||
}
|
||||
|
||||
var imageUrl = args.json.metadata?.imageUrl ?? args.json.imageUrl;
|
||||
var createdAt = args.json.created_at;
|
||||
var monthFolder = createdAt.slice(0, 7);
|
||||
@@ -10958,8 +10968,11 @@ console.log(`isLinux: ${LINUX}`);
|
||||
$app.data.instanceInventoryQueue = [];
|
||||
$app.data.instanceInventoryQueueWorker = null;
|
||||
|
||||
$app.methods.queueCheckInstanceInventory = function (inventoryId) {
|
||||
if (this.instanceInventoryCache.includes(inventoryId)) {
|
||||
$app.methods.queueCheckInstanceInventory = function (inventoryId, userId) {
|
||||
if (
|
||||
this.instanceInventoryCache.includes(inventoryId) ||
|
||||
this.instanceStickersCache.includes(inventoryId)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.instanceInventoryCache.push(inventoryId);
|
||||
@@ -10967,25 +10980,29 @@ console.log(`isLinux: ${LINUX}`);
|
||||
this.instanceInventoryCache.shift();
|
||||
}
|
||||
|
||||
this.instanceInventoryQueue.push(inventoryId);
|
||||
this.instanceInventoryQueue.push({ inventoryId, userId });
|
||||
|
||||
if (!this.instanceInventoryQueueWorker) {
|
||||
this.instanceInventoryQueueWorker = workerTimers.setInterval(() => {
|
||||
let inventoryId = this.instanceInventoryQueue.shift();
|
||||
if (inventoryId) {
|
||||
this.trySaveEmojiToFile(inventoryId);
|
||||
const item = this.instanceInventoryQueue.shift();
|
||||
if (item?.inventoryId) {
|
||||
this.trySaveEmojiToFile(item.inventoryId, item.userId);
|
||||
}
|
||||
}, 2_500);
|
||||
}
|
||||
};
|
||||
|
||||
$app.methods.trySaveEmojiToFile = async function (inventoryId) {
|
||||
const args = await inventoryRequest.getInventoryItem({
|
||||
inventoryId
|
||||
$app.methods.trySaveEmojiToFile = async function (inventoryId, userId) {
|
||||
const args = await inventoryRequest.getUserInventoryItem({
|
||||
inventoryId,
|
||||
userId
|
||||
});
|
||||
|
||||
if (args.json.itemType !== 'emoji') {
|
||||
// Not an emoji, skip
|
||||
if (
|
||||
args.json.itemType !== 'emoji' ||
|
||||
!args.json.flags.includes('ugc')
|
||||
) {
|
||||
// Not an emoji or ugc, skipping
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -283,16 +283,20 @@ export default class extends baseClass {
|
||||
|
||||
if ($app.saveInstanceEmoji) {
|
||||
try {
|
||||
// https://api.vrchat.cloud/api/1/inventory/spawn?id=inv_75781d65-92fe-4a80-a1ff-27ee6e843b08
|
||||
// https://api.vrchat.cloud/api/1/user/usr_032383a7-748c-4fb2-94e4-bcb928e5de6b/inventory/inv_75781d65-92fe-4a80-a1ff-27ee6e843b08
|
||||
const url = new URL(gameLog.url);
|
||||
if (
|
||||
url.pathname.substring(0, 22) ===
|
||||
'/api/1/inventory/spawn'
|
||||
url.pathname.substring(0, 12) ===
|
||||
'/api/1/user/' &&
|
||||
url.pathname.includes('/inventory/inv_')
|
||||
) {
|
||||
const inventoryId = url.searchParams.get('id');
|
||||
if (inventoryId && inventoryId.length === 40) {
|
||||
const pathArray = url.pathname.split('/');
|
||||
const userId = pathArray[4];
|
||||
const inventoryId = pathArray[6];
|
||||
if (userId && inventoryId.length === 40) {
|
||||
$app.queueCheckInstanceInventory(
|
||||
inventoryId
|
||||
inventoryId,
|
||||
userId
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -454,6 +458,7 @@ export default class extends baseClass {
|
||||
|
||||
$app.trySaveStickerToFile(
|
||||
gameLog.displayName,
|
||||
gameLog.userId,
|
||||
gameLog.inventoryId
|
||||
);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user