Automatic push 4.1.2

This commit is contained in:
chevereto
2024-05-06 17:49:12 +00:00
parent 89d66d15d4
commit f2ef7a981f
50 changed files with 487 additions and 337 deletions

View File

@@ -86,18 +86,10 @@ class Album
if ($requester !== []) {
$album_db['album_liked'] = (bool) $album_db['like_user_id'];
}
$return = $album_db;
if (isset($return['album_password']) && hasEncryption()) {
try {
$return['album_password'] = decrypt($return['album_password']);
} catch (Throwable) {
$return['album_password'] = $return['album_password'];
}
}
return $pretty
? self::formatArray($return)
: $return;
? self::formatArray($album_db)
: self::cipherAwareDbRow($album_db);
}
public static function getMultiple(array $ids, bool $pretty = false): array
@@ -514,8 +506,22 @@ class Album
$album['cta'] = $album['cta'] ?? '[]';
}
public static function cipherAwareDbRow(array &$dbrow): array
{
if (isset($dbrow['album_password']) && hasEncryption()) {
try {
$dbrow['album_password'] = decrypt($dbrow['album_password']);
} catch (Throwable) {
$dbrow['album_password'] = $dbrow['album_password'];
}
}
return $dbrow;
}
public static function formatArray(array $dbrow, bool $safe = false): array
{
self::cipherAwareDbRow($dbrow);
$output = DB::formatRow($dbrow);
if (!isset($output['user'])) {
$output['user'] = [];
@@ -555,7 +561,7 @@ class Album
if (isset($session_password) && hasEncryption()) {
$session_password = decrypt($session_password);
}
if (!isset($session_password) || !hash_equals($session_password, $album['password'])) {
if (!isset($session_password) || !hash_equals($album['password'], $session_password)) {
$removeValue = session()['password'] ?? null;
unset($removeValue['album'][$album['id']]);
sessionVar()->put('password', $removeValue);

View File

@@ -14,6 +14,8 @@ namespace Chevereto\Legacy\Classes;
use function Chevere\Message\message;
use function Chevere\String\randomString;
use Chevere\Throwable\Exceptions\LogicException;
use function Chevereto\Encryption\decrypt;
use function Chevereto\Encryption\hasEncryption;
use function Chevereto\Legacy\assertNotStopWords;
use function Chevereto\Legacy\decodeID;
use function Chevereto\Legacy\encodeID;
@@ -31,6 +33,7 @@ use function Chevereto\Legacy\G\format_bytes;
use function Chevereto\Legacy\G\get_basename_without_extension;
use function Chevereto\Legacy\G\get_bytes;
use function Chevereto\Legacy\G\get_client_ip;
use function Chevereto\Legacy\G\get_ffmpeg_error;
use function Chevereto\Legacy\G\get_filename;
use function Chevereto\Legacy\G\get_image_fileinfo as GGet_image_fileinfo;
use function Chevereto\Legacy\G\get_public_url;
@@ -790,9 +793,16 @@ class Image
}
$resizeSourceImage = $image_upload['uploaded']['file'];
$uploadDir = dirname($resizeSourceImage);
$chainExtension = $image_upload['uploaded']['extension'];
if ($image_upload['source']['type'] === 'video') {
$frameImage = $uploadDir . '/' . $image_upload['uploaded']['name'] . '.fr.jpeg';
$chainExtension = 'jpeg';
$frameImage = $uploadDir
. '/'
. $image_upload['uploaded']['name']
. '.fr.'
. $chainExtension;
rename($image_upload['uploaded']['frame'], $frameImage);
chmod($frameImage, 0644);
$resizeSourceImage = $frameImage;
$chain_mask[0] = 1;
}
@@ -810,11 +820,12 @@ class Image
} else {
$image_resize_options = ['width' => $params['width']];
}
$image_resize_options['extension'] = $image_upload['uploaded']['extension'];
$image_upload['uploaded'] = self::resize(
$resizeSourceImage,
dirname($resizeSourceImage),
null,
$image_resize_options
source: $resizeSourceImage,
destination: dirname($resizeSourceImage),
filename: null,
options: $image_resize_options
);
$image_upload['uploaded']['fileinfo']['is_360'] = $is_360;
}
@@ -824,6 +835,7 @@ class Image
'fitted' => true,
'width' => getSetting('upload_thumb_width'),
'height' => getSetting('upload_thumb_height'),
'extension' => $chainExtension
];
$medium_size = getSetting('upload_medium_size');
$medium_fixed_dimension = getSetting('upload_medium_fixed_dimension');
@@ -870,11 +882,12 @@ class Image
$image_medium_options['forced'] = true;
$image_medium_options[$medium_fixed_dimension] = min($image_medium_options[$medium_fixed_dimension], $image_upload['uploaded']['fileinfo'][$medium_fixed_dimension]);
}
$image_medium_options['extension'] = $chainExtension;
$image_medium = self::resize(
$resizeSourceImage,
$uploadDir,
$image_upload['uploaded']['name'] . '.md',
$image_medium_options
source: $resizeSourceImage,
destination: $uploadDir,
filename: $image_upload['uploaded']['name'] . '.md',
options: $image_medium_options
);
$chain_mask[3] = 1;
}
@@ -1246,6 +1259,7 @@ class Image
'original_filename' => $image_upload['source']['filename'],
'original_exifdata' => $original_exifdata,
'is_360' => $is360,
'extension' => $image_upload['uploaded']['extension'],
];
if (!isset($values['date'])) {
$populate_values = array_merge($populate_values, [
@@ -1478,7 +1492,6 @@ class Image
$image = array_merge($image, get_fileinfo($targets['chain']['image']), $image_fileinfo);
}
$image['file_resource'] = $targets;
$image['url_viewer'] = self::getUrlViewer(
$image['id_encoded'],
@@ -1518,6 +1531,7 @@ class Image
break;
}
$displaySize = $image['medium']['size'];
} elseif (
$image['size'] > get_bytes('200 KB')
&& $image['type'] === 1
@@ -1525,6 +1539,14 @@ class Image
$display_url = $image['thumb']['url'] ?? '';
$display_width = getSetting('upload_thumb_width');
$display_height = getSetting('upload_thumb_height');
$displaySize = $image['thumb']['size'];
}
if (isset($image['frame']['size'], $displaySize)
&& $image['frame']['size'] < $displaySize
) {
$display_url = $image['frame']['url'];
$display_width = $image['width'];
$display_height = $image['height'];
}
$image['duration'] = (int) ($image['duration'] ?? 0);
$seconds = $image['duration'] ?? 0;
@@ -1534,6 +1556,13 @@ class Image
} else {
$duration_time = '';
}
$image['medium'] = $image['medium'] ?? [
'filename' => null,
'name' => null,
'mime' => null,
'extension' => null,
'url' => null,
];
$image['duration_time'] = $duration_time;
$image['type'] = self::$types[$image['type']];
$image['display_url'] = $display_url;
@@ -1562,6 +1591,13 @@ class Image
}
if (isset($output['album']['id']) || isset($output['user']['id'])) {
$output['user'] = $output['user'] ?? [];
if (isset($output['album']['password']) && hasEncryption()) {
try {
$output['album']['password'] = decrypt($output['album']['password']);
} catch (Throwable) {
$output['album']['password'] = $output['album']['password'];
}
}
Album::fill($output['album'], $output['user']);
} else {
unset($output['album']);
@@ -1584,7 +1620,18 @@ class Image
public static function getVideoFrame(string $file, int $time): string
{
$frameFile = Upload::getTempNam(sys_get_temp_dir());
$ffmpeg = FFMpeg::create();
try {
$ffmpeg = FFMpeg::create(
[
'ffmpeg.binaries' => env()['CHEVERETO_BINARY_FFMPEG'],
'ffprobe.binaries' => env()['CHEVERETO_BINARY_FFPROBE'],
]
);
} catch (Throwable $e) {
throw new Exception("FFprobe error: " . get_ffmpeg_error($e), 600);
}
$video = $ffmpeg->open($file);
$video
->frame(TimeCode::fromSeconds($time))

View File

@@ -105,7 +105,8 @@ class ImageResize
{
$this->validateInput(); // Exception 1xx
$source_filename = get_basename_without_extension($this->source);
$this->file_extension = $this->source_image_fileinfo['extension'];
$this->file_extension = $this->options['extension']
?? $this->source_image_fileinfo['extension'];
if (!isset($this->filename)) {
$this->filename = $source_filename;
}

View File

@@ -83,9 +83,6 @@ class Search
str_replace($v, '', $q_match)
)
);
if ($q_match === '') {
$q_match = null;
}
$op = explode(':', $v);
if (!in_array($op[0], ['category', 'ip', 'storage'])) {
continue;
@@ -134,7 +131,7 @@ class Search
break;
}
}
if (isset($q_match)) {
if ($q_match !== '') {
$q_value = $q_match;
if ($this->DBEngine == 'InnoDB') {
$q_value = trim($q_value, '><');
@@ -146,7 +143,7 @@ class Search
$wheres = null;
switch ($this->type) {
case 'images':
if (isset($q_match)) {
if ($q_match !== '') {
$wheres = 'WHERE MATCH(`image_name`,`image_title`,`image_description`,`image_original_filename`) AGAINST (:q IN BOOLEAN MODE)';
}
if ($search_op_wheres !== []) {

View File

@@ -386,6 +386,16 @@ class Settings
'watermark_target_min_width' => '100',
]
],
'CHEVERETO_ENABLE_SEO_IMAGE_URL' => ['0',
[
'seo_image_urls' => false,
]
],
'CHEVERETO_ENABLE_SEO_ALBUM_URL' => ['0',
[
'seo_album_urls' => false,
]
],
] as $envKey => $settingValues) {
if (env()[$envKey] == $settingValues[0]) {
foreach ($settingValues[1] as $k => $v) {

View File

@@ -67,6 +67,8 @@ class Upload
private array|string $source;
private string $source_extension;
private array $uploaded = [];
public bool $detectFlood = true;
@@ -145,6 +147,10 @@ class Upload
$this->type = (is_image_url($this->source) || is_url($this->source))
? 'url'
: 'file';
$this->source_extension = $this->type === 'url'
? pathinfo($this->source, PATHINFO_EXTENSION)
: pathinfo($this->source['name'], PATHINFO_EXTENSION);
$this->source_extension = strtolower($this->source_extension);
if ($this->type === 'url') {
if (Settings::get('enable_uploads_url') === false) {
throw new LogicException(
@@ -202,6 +208,9 @@ class Upload
}
$this->source_name = get_basename_without_extension($this->type == 'url' ? $this->source : $this->source['name']);
$this->extension = $this->source_image_fileinfo['extension'];
if ($this->extension === 'jpeg' && $this->source_extension === 'jpg') {
$this->extension = 'jpg';
}
if (!isset($this->name)) {
$this->name = $this->source_name;
}
@@ -211,7 +220,7 @@ class Upload
}
$this->fixed_filename = preg_replace('/(.*)\.(th|md|original|lg)\.([\w]+)$/', '$1.$3', $this->name . '.' . $this->extension);
$is_360 = false;
if ($this->extension == 'jpeg') {
if (in_array($this->extension, ['jpg', 'jpeg'])) {
$xmpDataExtractor = new XmpMetadataExtractor();
$xmpData = $xmpDataExtractor->extractFromFile($this->downstream);
$reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_NATIVE);
@@ -319,6 +328,7 @@ class Upload
'fileinfo' => $fileInfo,
'frame' => $frameFile,
'frameinfo' => $frameFile ? get_image_fileinfo($frameFile) : [],
'extension' => $this->extension,
];
}

View File

@@ -1957,15 +1957,28 @@ function extension_to_mime(string $ext): string
][$ext] ?? '';
}
function get_ffmpeg_error(Throwable $e): string
{
$previous = $e->getPrevious() ?
(': ' . $e->getPrevious()->getMessage()) :
'';
return $e->getMessage() . $previous;
}
function get_video_fileinfo(string $file): array
{
clearstatcache(true, $file);
$ffprobe = FFProbe::create();
try {
$ffprobe = FFProbe::create(
[
'ffprobe.binaries' => env()['CHEVERETO_BINARY_FFPROBE'],
]
);
$format = $ffprobe->format($file);
} catch (Throwable $e) {
throw new Exception("FFprobe error: " . $e->getMessage(), 600);
throw new Exception("FFprobe error: " . get_ffmpeg_error($e), 600);
}
if (!($format->get('duration') > 0)) {
throw new Exception("Invalid video file provided", 100);

View File

@@ -1007,7 +1007,7 @@ function loaderHandler(
'CHEVERETO_ENABLE_BANNERS' => '0',
'CHEVERETO_ENABLE_BULK_IMPORTER' => '0',
'CHEVERETO_ENABLE_CAPTCHA' => '0',
'CHEVERETO_ENABLE_CDN' => '0',
'CHEVERETO_ENABLE_CDN' => '1',
'CHEVERETO_ENABLE_CONSENT_SCREEN' => '0',
'CHEVERETO_ENABLE_COOKIE_COMPLIANCE' => '0',
'CHEVERETO_ENABLE_EXPOSE_PAID_FEATURES' => '1',
@@ -1035,6 +1035,8 @@ function loaderHandler(
'CHEVERETO_ENABLE_UPLOAD_PLUGIN' => '0',
'CHEVERETO_ENABLE_UPLOAD_WATERMARK' => '0',
'CHEVERETO_ENABLE_USERS' => '0',
'CHEVERETO_ENABLE_SEO_IMAGE_URL' => '0',
'CHEVERETO_ENABLE_SEO_ALBUM_URL' => '0',
'CHEVERETO_MAX_USERS' => '1',
'CHEVERETO_EDITION' => 'free',
));