Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
184
Issues
184
List
Boards
Labels
Service Desk
Milestones
Merge Requests
33
Merge Requests
33
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
35a18615
Commit
35a18615
authored
3 hours ago
by
Marcelo Rivera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(feat): new api/v2/feeds/channel endpoint
parent
83c8a45d
epic/minds-pro
1 merge request
!281
WIP: (feat): Minds Pro
Pipeline
#73139701
failed with stages
in 17 minutes and 19 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
201 additions
and
0 deletions
+201
-0
channel.php
Controllers/api/v2/feeds/channel.php
+201
-0
No files found.
Controllers/api/v2/feeds/channel.php
0 → 100644
View file @
35a18615
<?php
/**
* @author: eiennohi.
*/
namespace
Minds\Controllers\api\v2\feeds
;
use
Minds\Api\Exportable
;
use
Minds\Api\Factory
;
use
Minds\Common\Repository\Response
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Entities\Factory
as
EntitiesFactory
;
use
Minds\Entities\User
;
use
Minds\Interfaces
;
class
channel
implements
Interfaces\Api
{
public
function
get
(
$pages
)
{
/** @var User $currentUser */
$currentUser
=
Core\Session
::
getLoggedinUser
();
//
$container_guid
=
$pages
[
0
]
??
null
;
if
(
!
$container_guid
)
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Invalid container'
,
]);
}
$container
=
EntitiesFactory
::
build
(
$container_guid
);
if
(
!
$container
||
!
Core\Security\ACL
::
_
()
->
read
(
$container
,
$currentUser
))
{
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
'Forbidden'
,
]);
}
$type
=
''
;
switch
(
$pages
[
1
])
{
case
'activities'
:
$type
=
'activity'
;
break
;
case
'images'
:
$type
=
'object:image'
;
break
;
case
'videos'
:
$type
=
'object:video'
;
break
;
case
'blogs'
:
$type
=
'object:blog'
;
break
;
}
//
$hardLimit
=
5000
;
$offset
=
0
;
if
(
isset
(
$_GET
[
'offset'
]))
{
$offset
=
intval
(
$_GET
[
'offset'
]);
}
$limit
=
12
;
if
(
isset
(
$_GET
[
'limit'
]))
{
$limit
=
abs
(
intval
(
$_GET
[
'limit'
]));
}
if
((
$offset
+
$limit
)
>
$hardLimit
)
{
$limit
=
$hardLimit
-
$offset
;
}
if
(
$limit
<=
0
)
{
return
Factory
::
response
([
'status'
=>
'success'
,
'entities'
=>
[],
'load-next'
=>
$hardLimit
,
'overflow'
=>
true
,
]);
}
//
$sync
=
(
bool
)
(
$_GET
[
'sync'
]
??
false
);
$fromTimestamp
=
$_GET
[
'from_timestamp'
]
??
0
;
$asActivities
=
(
bool
)
(
$_GET
[
'as_activities'
]
??
true
);
$forcePublic
=
(
bool
)
(
$_GET
[
'force_public'
]
??
false
);
$query
=
null
;
if
(
isset
(
$_GET
[
'query'
]))
{
$query
=
$_GET
[
'query'
];
}
$custom_type
=
isset
(
$_GET
[
'custom_type'
])
&&
$_GET
[
'custom_type'
]
?
[
$_GET
[
'custom_type'
]]
:
null
;
/** @var Core\Feeds\Top\Entities $entities */
$entities
=
new
Core\Feeds\Top\Entities
();
$entities
->
setActor
(
$currentUser
);
$isOwner
=
false
;
if
(
$currentUser
)
{
$entities
->
setActor
(
$currentUser
);
$isOwner
=
$currentUser
->
guid
==
$container_guid
;
}
$opts
=
[
'cache_key'
=>
$currentUser
?
$currentUser
->
guid
:
null
,
'container_guid'
=>
$container_guid
,
'access_id'
=>
$isOwner
&&
!
$forcePublic
?
[
0
,
1
,
2
,
$container_guid
]
:
[
2
,
$container_guid
],
'custom_type'
=>
$custom_type
,
'limit'
=>
$limit
,
'type'
=>
$type
,
'algorithm'
=>
'top'
,
'period'
=>
'1y'
,
'sync'
=>
$sync
,
'from_timestamp'
=>
$fromTimestamp
,
'query'
=>
$query
,
'single_owner_threshold'
=>
0
,
'pinned_guids'
=>
$type
===
'activity'
?
array_reverse
(
$container
->
getPinnedPosts
())
:
null
,
];
if
(
isset
(
$_GET
[
'nsfw'
]))
{
$nsfw
=
$_GET
[
'nsfw'
]
??
''
;
$opts
[
'nsfw'
]
=
explode
(
','
,
$nsfw
);
}
try
{
$result
=
$this
->
getData
(
$entities
,
$opts
,
$asActivities
,
$sync
);
if
(
$result
->
count
()
===
0
)
{
$opts
[
'algorithm'
]
=
'latest'
;
$result
=
$this
->
getData
(
$entities
,
$opts
,
$asActivities
,
$sync
);
}
return
Factory
::
response
([
'status'
=>
'success'
,
'entities'
=>
Exportable
::
_
(
$result
),
'load-next'
=>
$result
->
getPagingToken
(),
]);
}
catch
(
\Exception
$e
)
{
error_log
(
$e
);
return
Factory
::
response
([
'status'
=>
'error'
,
'message'
=>
$e
->
getMessage
()]);
}
}
/**
* @param Core\Feeds\Top\Entities $entities
* @param array $opts
* @param bool $asActivities
* @param bool $sync
* @return Response
* @throws \Exception
*/
private
function
getData
(
$entities
,
$opts
,
$asActivities
,
$sync
)
{
/** @var Core\Feeds\Top\Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Feeds\Top\Manager'
);
$result
=
$manager
->
getList
(
$opts
);
if
(
!
$sync
)
{
// Remove all unlisted content, if ES document is not in sync, it'll
// also remove pending activities
$result
=
$result
->
filter
([
$entities
,
'filter'
]);
if
(
$asActivities
)
{
// Cast to ephemeral Activity entities, if another type
$result
=
$result
->
map
([
$entities
,
'cast'
]);
}
}
return
$result
;
}
public
function
post
(
$pages
)
{
return
Factory
::
response
([]);
}
public
function
put
(
$pages
)
{
return
Factory
::
response
([]);
}
public
function
delete
(
$pages
)
{
return
Factory
::
response
([]);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment