Skip to content

Commit

Permalink
# This is a combination of 26 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

begin to implement front end of association-based search

# This is the commit message #2:

continue fleshing out the front and back end of association-based search

# This is the commit message #3:

rename some variables to be more accurate and fix a few array-vs-string handlers

# This is the commit message #4:

remove assistive-text lines

# This is the commit message #5:

fix issue with taxa suggest

# This is the commit message #6:

DRY up taxa suggest in a way that is usable for more than one element on the same page

# This is the commit message #7:

fix bug where reverse relationship was not returning results correctly

# This is the commit message #8:

begin to flesh out populating readRequestVariables with association-related data

# This is the commit message #9:

continue making progress with writing setAssociationRequestVariable method

# This is the commit message #10:

continue working on setAssociationRequestVariable and subfunctions

# This is the commit message #11:

continue subfunctionalizing

# This is the commit message #12:

continue fleshing out the associated-taxon query

# This is the commit message #13:

continue to make progress on the new search-by-association query infrastructure

# This is the commit message #14:

get search results to display

# This is the commit message #15:

Get the search criteria to display

# This is the commit message #16:

Update harvester.php (#1447)

Modifies logic to display available boundary tool when no active geographic thesaurus exist in the DB
# This is the commit message #17:

CSS drop-down menus (#1452)

* CSS drop-down menus

Add styling to header.css that enables top drop-down menus
# This is the commit message #18:

Update OmCollections.php (#1455)

Errant line of code short circuiting collection meta data update.
# This is the commit message #19:

closes #1449 which was preventing checklist polyaid from opening (#1458)


# This is the commit message #20:

Occurrence editor crowdsource adjustments

- Add formatting for eventDate2
- Adjust exsicati
- Remove from display: additional identifiers, behavior, vitality

# This is the commit message #21:

occurrence editor crowdsource adjustments

- Add vertical-align to crowdsource css to override value set within reset.css
- Force refresh of crowdsource.css within client's browsers

# This is the commit message #22:

crowdsource editor styling issue

- resolve vertical-align issue, which persisted when opening in crowdsourcing mode and then switching between long and short forms
- Fix fieldset padding issue within image popout

# This is the commit message #23:

Api media 2024 06 (#1463)

- Fix route bug interfering with POST write calls
- Add recordID UUID to POST call
- Improve error output media object isn't found (400 error)
- Improve standardization of all response output
- Add sort fields to api documentation
- Add function that attempts to determine mime type via file header. Has added benefit of ensuring input file exists.
- Update swagger documentation 

# This is the commit message #24:

Media API

- Add ability to match images based on recordID UUID within PATCH call

# This is the commit message #25:

added confirmation windows for project and editor delete icons (#1454)


# This is the commit message #26:

[3.1] -burpsuite-fix: do not add taxa to query if there are special characters or quotes (#1436)

* do not add taxa to query if there are special characters or quotes

* cherry pick fix in 6250abd where getTaxonWhereFrag was getting un-cleaned taxon string

* respond to code review feedback
  • Loading branch information
Atticus29 committed Aug 6, 2024
1 parent 40cc0b7 commit 8aaf78d
Show file tree
Hide file tree
Showing 33 changed files with 1,641 additions and 295 deletions.
120 changes: 79 additions & 41 deletions api/app/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
namespace App\Http\Controllers;

use App\Models\Media;
use App\Models\Occurrence;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Str;

class MediaController extends Controller{

private $rulesInsert = [
'apiToken' => 'required',
'originalUrl' => 'required',
'format' => 'required',
'occid' => 'integer|exists:omoccurrences,occid',
'tid' => 'integer|exists:taxa,tid',
'photographerUid' => 'integer|exists:users,uid'
Expand All @@ -29,7 +27,6 @@ public function __construct(){
parent::__construct();
$this->rulesUpdate = $this->rulesInsert;
unset($this->rulesUpdate['originalUrl']);
unset($this->rulesUpdate['format']);
}

/**
Expand Down Expand Up @@ -76,7 +73,11 @@ public function showAllMedia(){
* )
*/
public function showOneMedia($id){
return response()->json(Media::find($this->getImgid($id)));
$media = Media::find($this->getImgid($id));
if(!$media){
return response()->json(['status' => 'failure', 'error' => 'Media resource not found'], 400);
}
return response()->json($media);
}

/**
Expand All @@ -98,41 +99,42 @@ public function showOneMedia($id){
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* required={"format", "originalUrl"},
* required={"originalUrl"},
* @OA\Property(
* property="format",
* type="string",
* description="Media Type (MIME type)",
* maxLength=45
* maxLength=45,
* enum={"image/jpeg", "image/png", "image/tiff", "audio/wav"}
* ),
* @OA\Property(
* property="originalUrl",
* type="string",
* description="URL returning original large image; image should be a web-ready JPG",
* description="URL of original media file; images should be a web-ready JPG",
* maxLength=255
* ),
* @OA\Property(
* property="mediumUrl",
* type="string",
* description="URL returning medium sized image of original large image; image should be a web-ready JPG",
* description="URL of medium sized image of original image",
* maxLength=255
* ),
* @OA\Property(
* property="thumbnailUrl",
* type="string",
* description="URL returning thumbnail derivative of original large image; image should be a web-ready JPG",
* description="URL of thumbnail representation original media file",
* maxLength=255
* ),
* @OA\Property(
* property="archiveUrl",
* type="string",
* description="URL returning large archival image (e.g. DNG, TIFF, etc), if web accessible ",
* description="URL of archival media file (e.g. DNG, TIFF, etc), if publicly web accessible",
* maxLength=255
* ),
* @OA\Property(
* property="referenceUrl",
* type="string",
* description="URL returning original large image; image should be a web-ready JPG",
* description="URL of a web representation of media file. Maybe consist of html wrapper, viewer, player, etc",
* maxLength=255
* ),
* @OA\Property(
Expand Down Expand Up @@ -216,18 +218,22 @@ public function showOneMedia($id){
* description="Value computed by a hash function applied to the media that will be delivered at the access point",
* maxLength=45
* ),
* @OA\Property(
* property="sortSequence",
* type="integer",
* description="Media sort control within the taxon profile page"
* ),
* @OA\Property(
* property="sortOccurrence",
* type="integer",
* description="Media sort control within the occurrence profile page"
* ),
* ),
* )
* ),
* @OA\Response(
* response="201",
* description="Returns UUID recordID (GUID)",
* @OA\JsonContent(
* oneOf={
* @OA\Schema(@OA\Property(property="status", type="boolean"),@OA\Property(property="recordID", type="string")),
* @OA\Schema(@OA\Property(property="status", type="boolean"))
* },
* )
* description="Returns JSON object of the of media record that was created"
* ),
* @OA\Response(
* response="400",
Expand All @@ -241,10 +247,19 @@ public function showOneMedia($id){
*/
public function insert(Request $request){
if($user = $this->authenticate($request)){
$request->validate($this->rulesInsert);

$this->validate($request, $this->rulesInsert);
$inputArr = $request->all();
$this->adjustInputData($inputArr);
$inputArr['recordID'] = (string) Str::uuid();
if(!isset($inputArr['format'])){
$mimeType = $this->getMimeType($inputArr['originalUrl']);
if($mimeType && strpos($mimeType, 'text/html') === false){
$inputArr['format'] = $mimeType;
}
else{
return response()->json(['error' => 'format field required; unable to determine mime type dynamically'], 401);
}
}
$media = Media::create($inputArr);
return response()->json($media, 201);
}
Expand Down Expand Up @@ -276,41 +291,41 @@ public function insert(Request $request){
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* required={"format", "originalUrl"},
* @OA\Property(
* property="format",
* type="string",
* description="Media Type (MIME type)",
* maxLength=45
* maxLength=45,
* enum={"image/jpeg", "image/png", "image/tiff", "audio/wav"}
* ),
* @OA\Property(
* property="originalUrl",
* type="string",
* description="URL returning original large image; image should be a web-ready JPG",
* description="URL of original media file; images should be a web-ready JPG",
* maxLength=255
* ),
* @OA\Property(
* property="mediumUrl",
* type="string",
* description="URL returning medium sized image of original large image; image should be a web-ready JPG",
* description="URL of medium sized image of original image",
* maxLength=255
* ),
* @OA\Property(
* property="thumbnailUrl",
* type="string",
* description="URL returning thumbnail derivative of original large image; image should be a web-ready JPG",
* description="URL of thumbnail representation original media file",
* maxLength=255
* ),
* @OA\Property(
* property="archiveUrl",
* type="string",
* description="URL returning large archival image (e.g. DNG, TIFF, etc), if web accessible ",
* description="URL of archival media file (e.g. DNG, TIFF, etc), if publicly web accessible",
* maxLength=255
* ),
* @OA\Property(
* property="referenceUrl",
* type="string",
* description="URL returning original large image; image should be a web-ready JPG",
* description="URL of a web representation of media file. Maybe consist of html wrapper, viewer, player, etc",
* maxLength=255
* ),
* @OA\Property(
Expand Down Expand Up @@ -394,13 +409,22 @@ public function insert(Request $request){
* description="Value computed by a hash function applied to the media that will be delivered at the access point",
* maxLength=45
* ),
* @OA\Property(
* property="sortSequence",
* type="integer",
* description="Media sort control within the taxon profile page"
* ),
* @OA\Property(
* property="sortOccurrence",
* type="integer",
* description="Media sort control within the occurrence profile page"
* ),
* ),
* )
* ),
* @OA\Response(
* response="201",
* description="",
* @OA\JsonContent()
* response="200",
* description="Returns full JSON object of the of media record that was edited"
* ),
* @OA\Response(
* response="400",
Expand All @@ -414,9 +438,11 @@ public function insert(Request $request){
*/
public function update($id, Request $request){
if($user = $this->authenticate($request)){
$media = Media::findOrFail($id);
$media = Media::find($this->getImgid($id));
if(!$media){
return response()->json(['status' => 'failure', 'error' => 'Media resource not found'], 400);
}
$this->validate($request, $this->rulesUpdate);

$inputArr = $request->all();
$this->adjustInputData($inputArr);
$media->update($inputArr);
Expand Down Expand Up @@ -445,11 +471,8 @@ public function update($id, Request $request){
* @OA\Schema(type="string")
* ),
* @OA\Response(
* response="200",
* description="Record deleted successfully",
* @OA\JsonContent(
* @OA\Schema(@OA\Property(property="status", type="boolean"))
* )
* response="204",
* description="Record deleted successfully"
* ),
* @OA\Response(
* response="400",
Expand All @@ -463,10 +486,14 @@ public function update($id, Request $request){
*/
public function delete($id, Request $request){
if($user = $this->authenticate($request)){
Media::findOrFail($id)->delete();
return response('Media object deleted successfully', 200);
$media = Media::find($this->getImgid($id));
if(!$media){
return response()->json(['status' => 'failure', 'error' => 'Media resource not found'], 400);
}
$media->delete();
return response('', 200);
}
return response()->json(['error' => 'Unauthorized'], 401);
return response()->json(['status' => 'failure', 'error' => 'Unauthorized'], 401);
}

private function adjustInputData(&$data){
Expand All @@ -484,4 +511,15 @@ private function getImgid($id){
}
return $id;
}

private function getMimeType($url){
$mimeType = '';
$headerArr = get_headers($url);
foreach($headerArr as $value){
if(preg_match('/Content-Type: (.*)/', $value, $m)){
$mimeType = $m[1];
}
}
return $mimeType;
}
}
3 changes: 1 addition & 2 deletions api/app/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class Media extends Model{

protected $fillable = [ 'url', 'thumbnailUrl', 'originalUrl', 'archiveUrl', 'tid', 'photographer', 'photographerUid', 'imageType', 'format', 'caption', 'owner', 'sourceUrl', 'referenceUrl',
'copyright', 'rights', 'accessRights', 'locality', 'occid', 'notes', 'anatomy', 'username', 'sourceIdentifier', 'hashFunction', 'hashValue', 'mediaMD5', 'dynamicProperties',
'defaultDisplay', 'sortSequence', 'sortOccurrence'
];
'defaultDisplay', 'sortSequence', 'sortOccurrence', 'recordID' ];
protected $guarded = [];
protected $hidden = ['dynamicProperties', 'username', 'defaultDisplay'];
private $serverDomain;
Expand Down
2 changes: 1 addition & 1 deletion api/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

$router->get('media', ['uses' => 'MediaController@showAllMedia']);
$router->get('media/{id}', ['uses' => 'MediaController@showOneMedia']);
$router->post('media', ['uses' => 'MediaController@insertMedia']);
$router->post('media', ['uses' => 'MediaController@insert']);
$router->patch('media/{id}', ['uses' => 'MediaController@update']);
$router->delete('media/{id}', ['uses' => 'MediaController@delete']);

Expand Down
Loading

0 comments on commit 8aaf78d

Please sign in to comment.