diff --git a/hwe/j_image_upload.php b/hwe/j_image_upload.php deleted file mode 100644 index 582b6864..00000000 --- a/hwe/j_image_upload.php +++ /dev/null @@ -1,111 +0,0 @@ -setReadOnly(); -$userID = $session::getUserID(); -$serverID = UniqueConst::$serverID; - -$image = $_FILES['img']; -switch ($image['error']) { - case UPLOAD_ERR_OK: - break; - case UPLOAD_ERR_NO_FILE: - Json::die([ - 'result'=>false, - 'reason'=>'파일이 없습니다.' - ]); - case UPLOAD_ERR_INI_SIZE: - case UPLOAD_ERR_FORM_SIZE: - Json::die([ - 'result'=>false, - 'reason'=>'업로드된 파일이 지나치게 큽니다.' - ]); - default: - Json::die([ - 'result'=>false, - 'reason'=>'업로드되지 않았습니다.' - ]); -} - -if(!is_uploaded_file($image['tmp_name'])) { - Json::die([ - 'result'=>false, - 'reason'=>'제대로 파일이 업로드되지 않았습니다.' - ]); -} - -if($image['size'] > 1048576) { - //파일크기 검사 - Json::die([ - 'result'=>false, - 'reason'=>'1MB 이하로 올려주세요!' - ]); -} - -$size = getImageSize($image['tmp_name']); - -$imageType = $size[2]; -$availableImageType = array('.jpg'=>IMAGETYPE_JPEG, '.png'=>IMAGETYPE_PNG, '.gif'=>IMAGETYPE_GIF); -$newExt = array_search($imageType, $availableImageType, true); - -if(!$newExt) { - Json::die([ - 'result'=>false, - 'reason'=>'jpg, gif, png 파일이 아닙니다!' - ]); -} - -$db = RootDB::db(); -$imgStor = KVStorage::getStorage($db, 'img_storage'); - -$picName = hash_file('md5', $image['tmp_name']); -$newPicName = "$picName$newExt"; - -$destDir = AppConf::getUserIconPathFS().'/uploaded_image'; -$dest = $destDir.'/'.$newPicName; - -if(!file_exists($dest)){ - if (!file_exists($destDir)) { - mkdir($destDir); - } - if(!is_dir($destDir)) { - Json::die([ - 'result'=>false, - 'reason'=>'버그! 업로드 경로 확인!' - ]); - } - if(!is_writable($destDir)){ - Json::die([ - 'result'=>false, - 'reason'=>'버그! 업로드 권한 확인!' - ]); - } - - $dest = $destDir.'/'.$newPicName; - - if(!move_uploaded_file($image['tmp_name'], $dest)) { - Json::die([ - 'result'=>false, - 'reason'=>'업로드에 실패했습니다!' - ]); - } -} - -$storedStatus = $imgStor->$newPicName??[]; -$imgKey = "$serverID:$userID"; -if(!key_exists($imgKey, $storedStatus)){ - $storedStatus[$imgKey] = TimeUtil::now(); -} - -$imgStor->$newPicName = $storedStatus; - -Json::die([ - 'result'=>true, - 'reason'=>'성공', - 'path'=>AppConf::getUserIconPathWeb().'/uploaded_image/'.$newPicName -]); \ No newline at end of file diff --git a/hwe/sammo/API/Misc/UploadImage.php b/hwe/sammo/API/Misc/UploadImage.php new file mode 100644 index 00000000..0fdb9226 --- /dev/null +++ b/hwe/sammo/API/Misc/UploadImage.php @@ -0,0 +1,101 @@ +args); + $v->rule('required', [ + 'imageData', + ]); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $imageData = base64_decode($this->args['imageData'], true); + if ($imageData === false) { + return "올바른 데이터가 아닙니다."; + } + + if(strlen($imageData) > 1024*1024){ + //NOTE: 가변 길이를 적용해야할까? + return "이미지 크기가 1MB보다 큽니다."; + } + + $contentType = (new \finfo(FILEINFO_MIME_TYPE))->buffer($imageData); + if (substr($contentType, 0, 5) !== 'image') { + return '이미지 파일이 아닙니다: ' . $contentType; + } + + $extension = ltrim($contentType, 'image/'); + $validExtensions = ['png', 'jpeg', 'jpg', 'gif', 'webp']; + if (!in_array(strtolower($extension), $validExtensions)) { + return '지원하지 않는 이미지 파일입니다: ' . $contentType; + } + + $oMD = hash_init('md5'); + hash_update($oMD, $imageData); + $imgName = hash_final($oMD); + $imgFullName = "{$imgName}.{$extension}"; + + $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_put_contents($destPath, $imageData)) { + return '업로드에 실패했습니다!'; + } + } + + $db = RootDB::db(); + $imgStor = KVStorage::getStorage($db, 'img_storage'); + + + $userID = $session->userID; + $serverID = UniqueConst::$serverID; + + $storedStatus = $imgStor->$imgFullName ?? []; + $imgKey = "$serverID:$userID"; + if (!key_exists($imgKey, $storedStatus)) { + $storedStatus[$imgKey] = TimeUtil::now(); + } + + $imgStor->$imgFullName = $storedStatus; + + return [ + 'result' => true, + 'path'=>AppConf::getUserIconPathWeb().'/uploaded_image/'.$imgFullName, + ]; + } +} diff --git a/hwe/scss/editor_component.scss b/hwe/scss/editor_component.scss new file mode 100644 index 00000000..6e084649 --- /dev/null +++ b/hwe/scss/editor_component.scss @@ -0,0 +1,46 @@ +.custom-image-original { + max-width: 100%; + display: block; +} + +.custom-image-large { + width: 100%; + display: block; +} + +.custom-image-medium { + width: 50%; + display: block; +} + +.custom-image-small { + margin: auto; + width: 25%; +} + +.custom-image-align-float-left{ + float: left; +} + +.custom-image-align-float-right{ + float: right; +} + +.custom-image-align-center{ + margin-left: auto; + margin-right: auto; + display: block; + +} +.custom-image-align-left{ + margin-left: 0; + margin-right: auto; + display: block; + +} + +.custom-image-align-right{ + margin-left: auto; + margin-right: 0; + display: block; +} diff --git a/hwe/ts/PartialDipcenter.vue b/hwe/ts/PartialDipcenter.vue index 3bfbf963..fd025887 100644 --- a/hwe/ts/PartialDipcenter.vue +++ b/hwe/ts/PartialDipcenter.vue @@ -48,6 +48,7 @@