Merge branch 'master' into develop

This commit is contained in:
Barış Soner Uşaklı
2025-02-18 11:43:52 -05:00
5 changed files with 24 additions and 10 deletions

View File

@@ -229,6 +229,10 @@ Notes.assertPrivate = async (object) => {
// Given an object, adds it to an existing chat or creates a new chat otherwise // Given an object, adds it to an existing chat or creates a new chat otherwise
// todo: context stuff // todo: context stuff
if (!object || !object.id || !activitypub.helpers.isUri(object.id)) {
return null;
}
const localUids = []; const localUids = [];
const recipients = new Set([...object.to, ...object.cc]); const recipients = new Set([...object.to, ...object.cc]);
await Promise.all(Array.from(recipients).map(async (value) => { await Promise.all(Array.from(recipients).map(async (value) => {

View File

@@ -52,6 +52,9 @@ utils.tokens.get = async (tokens) => {
}; };
utils.tokens.generate = async ({ uid, description }) => { utils.tokens.generate = async ({ uid, description }) => {
if (!srcUtils.isNumber(uid)) {
throw new Error('[[error:invalid-uid]]');
}
if (parseInt(uid, 10) !== 0) { if (parseInt(uid, 10) !== 0) {
const uidExists = await user.exists(uid); const uidExists = await user.exists(uid);
if (!uidExists) { if (!uidExists) {
@@ -66,7 +69,7 @@ utils.tokens.generate = async ({ uid, description }) => {
}; };
utils.tokens.add = async ({ token, uid, description = '', timestamp = Date.now() }) => { utils.tokens.add = async ({ token, uid, description = '', timestamp = Date.now() }) => {
if (!token || uid === undefined) { if (!token || uid === undefined || !srcUtils.isNumber(uid)) {
throw new Error('[[error:invalid-data]]'); throw new Error('[[error:invalid-data]]');
} }
@@ -80,6 +83,9 @@ utils.tokens.add = async ({ token, uid, description = '', timestamp = Date.now()
}; };
utils.tokens.update = async (token, { uid, description }) => { utils.tokens.update = async (token, { uid, description }) => {
if (!srcUtils.isNumber(uid)) {
throw new Error('[[error:invalid-uid]]');
}
await Promise.all([ await Promise.all([
db.setObject(`token:${token}`, { uid, description }), db.setObject(`token:${token}`, { uid, description }),
db.sortedSetAdd(`tokens:uid`, uid, token), db.sortedSetAdd(`tokens:uid`, uid, token),

View File

@@ -11,8 +11,6 @@ const privileges = require('../privileges');
const activitypub = require('../activitypub'); const activitypub = require('../activitypub');
const utils = require('../utils'); const utils = require('../utils');
const isEmojiShortcode = /^:[\w]+:$/;
module.exports = function (Posts) { module.exports = function (Posts) {
Posts.create = async function (data) { Posts.create = async function (data) {
// This is an internal method, consider using Topics.reply instead // This is an internal method, consider using Topics.reply instead
@@ -54,9 +52,15 @@ module.exports = function (Posts) {
if (_activitypub && _activitypub.tag && Array.isArray(_activitypub.tag)) { if (_activitypub && _activitypub.tag && Array.isArray(_activitypub.tag)) {
_activitypub.tag _activitypub.tag
.filter(tag => tag.type === 'Emoji' && .filter(tag => tag.type === 'Emoji' &&
isEmojiShortcode.test(tag.name) && tag.icon && tag.icon.type === 'Image')
tag.icon && tag.icon.mediaType && tag.icon.mediaType.startsWith('image/'))
.forEach((tag) => { .forEach((tag) => {
if (!tag.name.startsWith(':')) {
tag.name = `:${tag.name}`;
}
if (!tag.name.endsWith(':')) {
tag.name = `${tag.name}:`;
}
postData.content = postData.content.replace(new RegExp(tag.name, 'g'), `<img class="not-responsive emoji" src="${tag.icon.url}" title="${tag.name}" />`); postData.content = postData.content.replace(new RegExp(tag.name, 'g'), `<img class="not-responsive emoji" src="${tag.icon.url}" title="${tag.name}" />`);
}); });
} }

View File

@@ -1,13 +1,13 @@
<form role="form"> <form role="form">
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="uid">[[admin/settings/api:uid]]</label> <label class="form-label" for="uid">[[admin/settings/api:uid]]</label>
<input type="text" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="0" value="{./uid}" /> <input id="uid" type="number" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="0" value="{./uid}" />
<p class="form-text"> <p class="form-text">
[[admin/settings/api:uid-help-text]] [[admin/settings/api:uid-help-text]]
</p> </p>
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label" for="description">[[admin/settings/api:description]]</label> <label class="form-label" for="description">[[admin/settings/api:description]]</label>
<input type="text" name="description" class="form-control" placeholder="Description" value="{./description}" /> <input id="description" type="text" name="description" class="form-control" placeholder="Description" value="{./description}" />
</div> </div>
</form> </form>

View File

@@ -128,7 +128,7 @@ describe('Analytics', () => {
let counters; let counters;
({ counters } = analytics.peek()); ({ counters } = analytics.peek());
const before = { ...counters }; const before = { ...counters };
const { setTimeout } = require('timers/promises');
const id = `https://example.org/activity/${utils.generateUUID()}`; const id = `https://example.org/activity/${utils.generateUUID()}`;
await controllers.activitypub.postInbox({ await controllers.activitypub.postInbox({
body: { body: {
@@ -141,13 +141,13 @@ describe('Analytics', () => {
}, },
}, },
}, { sendStatus: () => {} }); }, { sendStatus: () => {} });
await setTimeout(2000);
({ counters } = analytics.peek()); ({ counters } = analytics.peek());
const after = { ...counters }; const after = { ...counters };
const metrics = ['activities', 'activities:byType:Like', 'activities:byHost:example.org']; const metrics = ['activities', 'activities:byType:Like', 'activities:byHost:example.org'];
metrics.forEach((metric) => { metrics.forEach((metric) => {
assert(before[metric] && after[metric]); assert(before[metric] && after[metric], JSON.stringify({ before, after }, null, 2));
assert(before[metric] < after[metric]); assert(before[metric] < after[metric]);
}); });
}); });