feat: upload editor images to image service
This commit is contained in:
@@ -8,6 +8,7 @@ use sammo\AppConf;
|
||||
use sammo\Enums\APIRecoveryType;
|
||||
use sammo\KVStorage;
|
||||
use sammo\RootDB;
|
||||
use sammo\RemoteUserIconUploadClient;
|
||||
use sammo\TimeUtil;
|
||||
use sammo\UniqueConst;
|
||||
use sammo\Validator;
|
||||
@@ -60,22 +61,33 @@ class UploadImage extends \sammo\BaseAPI
|
||||
$imgName = hash_final($oMD);
|
||||
$imgFullName = "{$imgName}.{$extension}";
|
||||
|
||||
$destDir = AppConf::getUserIconPathFS() . '/uploaded_image';
|
||||
$destPath = "{$destDir}/{$imgFullName}";
|
||||
$remotePath = null;
|
||||
if (RemoteUserIconUploadClient::isConfiguredEnabled()) {
|
||||
try {
|
||||
RemoteUserIconUploadClient::uploadContentConfigured($imgFullName, $contentType, $imageData);
|
||||
$remotePath = RemoteUserIconUploadClient::getConfiguredContentPublicUrl($imgFullName);
|
||||
} catch (\Throwable $error) {
|
||||
error_log('Remote content image upload failed: ' . $error->getMessage());
|
||||
return '원격 이미지 저장소 업로드에 실패했습니다!';
|
||||
}
|
||||
} else {
|
||||
$destDir = AppConf::getUserIconPathFS() . '/uploaded_image';
|
||||
$destPath = "{$destDir}/{$imgFullName}";
|
||||
|
||||
if (!file_exists($destPath)) {
|
||||
if (!file_exists($destDir)) {
|
||||
mkdir($destDir);
|
||||
}
|
||||
if (!is_dir($destDir)) {
|
||||
return '버그! 업로드 경로 확인!';
|
||||
}
|
||||
if (!is_writable($destDir)) {
|
||||
return '버그! 업로드 권한 확인!';
|
||||
}
|
||||
if (!file_exists($destPath)) {
|
||||
if (!file_exists($destDir)) {
|
||||
mkdir($destDir);
|
||||
}
|
||||
if (!is_dir($destDir)) {
|
||||
return '버그! 업로드 경로 확인!';
|
||||
}
|
||||
if (!is_writable($destDir)) {
|
||||
return '버그! 업로드 권한 확인!';
|
||||
}
|
||||
|
||||
if (!file_put_contents($destPath, $imageData)) {
|
||||
return '업로드에 실패했습니다!';
|
||||
if (!file_put_contents($destPath, $imageData)) {
|
||||
return '업로드에 실패했습니다!';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +108,7 @@ class UploadImage extends \sammo\BaseAPI
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'path'=>AppConf::getUserIconPathWeb().'/uploaded_image/'.$imgFullName,
|
||||
'path'=>$remotePath ?? AppConf::getUserIconPathWeb().'/uploaded_image/'.$imgFullName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user