Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xfmg/init #104

Open
wants to merge 27 commits into
base: xenforo2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
05136d4
create Controller\Album
datbth Oct 1, 2018
03d53cb
Merge remote-tracking branch 'upstream/xenforo2' into XFMG/init
datbth Nov 29, 2018
a9397bc
add actionIndex and actionSingle for albums
datbth Dec 1, 2018
7af96ed
added Api controller for media
datbth Dec 2, 2018
e9ac714
include date fields for albums
datbth Dec 2, 2018
109d1e3
add actionPostIndex for media
datbth Dec 2, 2018
c081fc3
add data to Transform/MediaItem
datbth Dec 2, 2018
84344a5
fix routing
datbth Dec 3, 2018
111af99
add actionPutIndex for albums
datbth Dec 3, 2018
153a5a3
add actionPostIndex for albums
datbth Dec 3, 2018
475373c
refactor getAttachmentTempHash to not require param attachment_hash
datbth Dec 5, 2018
1501ad1
add actionPutIndex for media
datbth Dec 5, 2018
c66accb
add actionDeleteIndex for albums
datbth Dec 5, 2018
227980a
add some filters for album listing
datbth Dec 5, 2018
08c7e5d
add actionDeleteIndex for media
datbth Dec 5, 2018
9a93e43
remove unnecessary detachEntity in album controller
datbth Dec 5, 2018
e4cccd9
refactor controllers
datbth Dec 5, 2018
fa936f4
fix AbstractController
datbth Dec 5, 2018
d853811
add like actions for album
datbth Dec 5, 2018
cb7f4a3
add like actions for media
datbth Dec 5, 2018
638f7a1
add is_liked field to Transform\Album and Transform\Media
datbth Dec 5, 2018
a3d27f3
implement follow APIs for albums
datbth Dec 9, 2018
0ef09b1
implement follow APIs for media
datbth Dec 9, 2018
09979fe
add links to API response for album and media
datbth Dec 9, 2018
da7a602
add permissions data to API response for albums and media
datbth Dec 9, 2018
9bbccf1
add basic APIs for comments
datbth Dec 9, 2018
30af829
revert changes in _output/templates/_metadata.json
datbth Dec 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Controller/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function actionPostAttachments()
$attachmentPlugin = $this->plugin('Xfrocks\Api:Attachment');
$tempHash = $attachmentPlugin->getAttachmentTempHash($contentData);

return $attachmentPlugin->doUpload($tempHash, 'conversation_message', $contentData);
return $attachmentPlugin->doUploadAndRespond($tempHash, 'conversation_message', $contentData);
}

protected function assertViewableConversation($conversationId, array $extraWith = [])
Expand Down
2 changes: 1 addition & 1 deletion Controller/ConversationMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function actionPostAttachments()
$attachmentPlugin = $this->plugin('Xfrocks\Api:Attachment');
$tempHash = $attachmentPlugin->getAttachmentTempHash($context);

return $attachmentPlugin->doUpload($tempHash, 'conversation_message', $context);
return $attachmentPlugin->doUploadAndRespond($tempHash, 'conversation_message', $context);
}

public function actionPostReport(ParameterBag $params)
Expand Down
2 changes: 1 addition & 1 deletion Controller/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function actionPostAttachments()
$attachmentPlugin = $this->plugin('Xfrocks\Api:Attachment');
$tempHash = $attachmentPlugin->getAttachmentTempHash($context);

return $attachmentPlugin->doUpload($tempHash, 'post', $context);
return $attachmentPlugin->doUploadAndRespond($tempHash, 'post', $context);
}

public function actionGetLikes(ParameterBag $params)
Expand Down
2 changes: 1 addition & 1 deletion Controller/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function actionPostAttachments()
$attachmentPlugin = $this->plugin('Xfrocks\Api:Attachment');
$tempHash = $attachmentPlugin->getAttachmentTempHash($context);

return $attachmentPlugin->doUpload($tempHash, 'post', $context);
return $attachmentPlugin->doUploadAndRespond($tempHash, 'post', $context);
}

public function actionGetFollowers(ParameterBag $params)
Expand Down
17 changes: 14 additions & 3 deletions ControllerPlugin/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ public function doUpload($hash, $contentType, $context, $formField = 'file')
if (!$attachment) {
throw $this->controller->exception($this->controller->noPermission($error));
}
return $attachment;
}

public function doUploadAndRespond($hash, $contentType, $context, $formField = 'file')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tại sao cần implement cái này nhỉ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dạ bên POST /media lưu file thành attachment nhưng không respond cái attachment nên em tách ra cái function doUpload riêng

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

À hiểu rồi. Thôi như đã bàn thì cứ để nó upload riêng và save riêng nha.

{
$attachment = $this->doUpload($hash, $contentType, $context, $formField);

/** @var AbstractController $controller */
$controller = $this->controller;
$lazyTransformer = $controller->transformEntityLazily($attachment);
$lazyTransformer->addCallbackPreTransform(function ($context) use ($hash) {
/** @var TransformContext $context */
Expand All @@ -64,10 +72,9 @@ public function getAttachmentTempHash(array $contentData = [])
$params = $controller->params();

$prefix = '';
$inputHash = $params['attachment_hash'];

if (!empty($inputHash)) {
$prefix = sprintf('hash%s', $inputHash);
if (!empty($params['attachment_hash'])) {
daohoangson marked this conversation as resolved.
Show resolved Hide resolved
$prefix = sprintf('hash%s', $params['attachment_hash']);
} elseif (!empty($contentData['post_id'])) {
$prefix = sprintf('post%d', $contentData['post_id']);
} elseif (!empty($contentData['thread_id'])) {
Expand All @@ -80,6 +87,10 @@ public function getAttachmentTempHash(array $contentData = [])
$prefix = sprintf('message%d', $contentData['message_id']);
} elseif (!empty($contentData['conversation_id'])) {
$prefix = sprintf('conversation%d', $contentData['conversation_id']);
} elseif (!empty($contentData['media_album_id'])) {
$prefix = sprintf('media_album%d', $contentData['media_album_id']);
} elseif (!empty($contentData['media_category_id'])) {
$prefix = sprintf('media_category%d', $contentData['media_category_id']);
}

/** @var Session $session */
Expand Down
6 changes: 6 additions & 0 deletions Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public static function appSetup($app)
if (!empty($addOnCache['XFRM'])) {
$extension->addClassExtension('Xfrocks\Api\Data\Modules', 'Xfrocks\Api\XFRM\Data\Modules');
}

$addOnCache = $container['addon.cache'];
$extension = $app->extension();
if (!empty($addOnCache['XFMG'])) {
$extension->addClassExtension('Xfrocks\Api\Data\Modules', 'Xfrocks\Api\XFMG\Data\Modules');
}
}

/**
Expand Down
81 changes: 81 additions & 0 deletions XFMG/Controller/AbstractController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Created by PhpStorm.
* User: datbth
* Date: 05/12/2018
* Time: 21:39
*/

namespace Xfrocks\Api\XFMG\Controller;

abstract class AbstractController extends \Xfrocks\Api\Controller\AbstractController
{
/**
* @param int $albumId
* @param array $extraWith
* @return \XFMG\Entity\Album
* @throws \XF\Mvc\Reply\Exception
*/
protected function assertViewableAlbum($albumId, array $extraWith = [])
{
/** @var \XFMG\Entity\Album $album */
$album = $this->assertRecordExists(
'XFMG:Album',
$albumId,
$extraWith,
'xfmg_requested_album_not_found'
);

if (!$album->canView($error)) {
throw $this->exception($this->noPermission($error));
}

return $album;
}

/**
* @param int $categoryId
* @param array $extraWith
* @return \XFMG\Entity\Category
* @throws \XF\Mvc\Reply\Exception
*/
protected function assertViewableCategory($categoryId, array $extraWith = [])
{
/** @var \XFMG\Entity\Category $category */
$category = $this->assertRecordExists(
'XFMG:Category',
$categoryId,
$extraWith,
'xfmg_requested_category_not_found'
);

if (!$category->canView($error)) {
throw $this->exception($this->noPermission($error));
}

return $category;
}

/**
* @param int $mediaId
* @param array $extraWith
* @return \XFMG\Entity\MediaItem
* @throws \XF\Mvc\Reply\Exception
*/
protected function assertViewableMediaItem($mediaId, array $extraWith = [])
{
/** @var \XFMG\Entity\MediaItem $item */
$item = $this->assertRecordExists(
'XFMG:MediaItem',
$mediaId,
$extraWith,
'xfmg_requested_media_item_not_found'
);

if (!$item->canView($error)) {
throw $this->exception($this->noPermission($error));
}

return $item;
}
}
Loading