duplicated images revisited

This commit is contained in:
Mike Macgirvin 2023-02-05 11:55:19 +11:00
parent f4ae615bad
commit 9ee206267c
3 changed files with 38 additions and 7 deletions

View file

@ -592,11 +592,14 @@ class Activity
$atts = ((is_array($item['attach'])) ? $item['attach'] : json_decode($item['attach'], true));
if ($atts) {
foreach ($atts as $att) {
$name = '';
if (isset($att['type']) && str_contains($att['type'], 'image')) {
if (!empty($att['href'])) {
$name = ($att['title']) ?? '';
if ($att['name']) {
$name = $att['name'];
}
if (! $name) {
$name = ($att['name']) ?? '';
$name = $att['title'];
}
$ret[] = [
'type' => 'Image',
@ -939,11 +942,15 @@ class Activity
$activity['tag'] = $t;
}
$a = self::encode_attachment($item);
if ($a) {
$activity['attachment'] = $a;
if ($obj && $obj['attachment']) {
$activity['attachment'] = $obj['attachment'];
}
else {
$a = self::encode_attachment($item);
if ($a) {
$activity['attachment'] = $a;
}
}
// addressing madness

View file

@ -44,6 +44,7 @@ use App;
use URLify;
require_once('include/attach.php');
require_once('include/photos.php');
require_once('include/bbcode.php');
require_once('include/security.php');
@ -1143,8 +1144,15 @@ class Item extends Controller
else {
$r = attach_by_hash_nodata($hash, $observer['xchan_hash'], $rev);
if ($r['success']) {
$href = z_root() . '/attach/' . $r['data']['hash'];
if ($r['data']['is_photo']) {
$href = z_root() . '/photo/' . $r['data']['hash'] . '-1.' . photoExtensionFromType($r['data']['filetype']);
if ($token) {
$href .= '?token=' . $token;
}
}
$attachments[] = [
'href' => z_root() . '/attach/' . $r['data']['hash'],
'href' => $href,
'length' => $r['data']['filesize'],
'type' => $r['data']['filetype'],
'title' => urlencode($r['data']['filename']),

View file

@ -575,6 +575,7 @@ function photo_upload($channel, $observer, $args)
$ret['success'] = true;
$ret['item'] = $arr;
$ret['body'] = $obj_body;
$ret['filename'] = $url[1]['href'];
$ret['resource_id'] = $photo_hash;
$ret['photoitem_id'] = $item_id;
@ -1049,6 +1050,21 @@ function profile_photo_set_profile_perms($uid, $profileid = 0)
}
}
function photoExtensionFromType($type)
{
$t = [
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif',
'image/webp' => 'webp',
];
return ($t[$type]) ?? '';
}
function fetch_image_from_url($url, &$mimetype)
{
$x = Url::get($url, [ 'novalidate' => true ]);