mirror of https://github.com/pixelfed/pixelfed
commit
255c41fb83
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\FollowPipeline;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
use Cache, Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use App\FollowRequest;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Transformer\ActivityPub\Verb\AcceptFollow;
|
||||
|
||||
class FollowAcceptPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $followRequest;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(FollowRequest $followRequest)
|
||||
{
|
||||
$this->followRequest = $followRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$follow = $this->followRequest;
|
||||
$actor = $follow->actor;
|
||||
$target = $follow->target;
|
||||
|
||||
if($actor->domain == null || $actor->inbox_url == null || !$target->private_key) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($follow, new AcceptFollow());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
$url = $actor->sharedInbox ?? $actor->inbox_url;
|
||||
|
||||
Helpers::sendSignedObject($target, $url, $activity);
|
||||
|
||||
$follow->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\FollowPipeline;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
use Cache, Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use App\FollowRequest;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Transformer\ActivityPub\Verb\RejectFollow;
|
||||
|
||||
class FollowRejectPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $followRequest;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(FollowRequest $followRequest)
|
||||
{
|
||||
$this->followRequest = $followRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$follow = $this->followRequest;
|
||||
$actor = $follow->actor;
|
||||
$target = $follow->target;
|
||||
|
||||
if($actor->domain == null || $actor->inbox_url == null || !$target->private_key) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($follow, new RejectFollow());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
$url = $actor->sharedInbox ?? $actor->inbox_url;
|
||||
|
||||
Helpers::sendSignedObject($target, $url, $activity);
|
||||
|
||||
$follow->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\{
|
||||
Profile,
|
||||
Status,
|
||||
UserFilter
|
||||
};
|
||||
|
||||
class NetworkTimelineService
|
||||
{
|
||||
const CACHE_KEY = 'pf:services:timeline:network';
|
||||
|
||||
public static function get($start = 0, $stop = 10)
|
||||
{
|
||||
if($stop > 100) {
|
||||
$stop = 100;
|
||||
}
|
||||
|
||||
return Redis::zrevrange(self::CACHE_KEY, $start, $stop);
|
||||
}
|
||||
|
||||
public static function getRankedMaxId($start = null, $limit = 10)
|
||||
{
|
||||
if(!$start) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_keys(Redis::zrevrangebyscore(self::CACHE_KEY, $start, '-inf', [
|
||||
'withscores' => true,
|
||||
'limit' => [1, $limit]
|
||||
]));
|
||||
}
|
||||
|
||||
public static function getRankedMinId($end = null, $limit = 10)
|
||||
{
|
||||
if(!$end) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_keys(Redis::zrevrangebyscore(self::CACHE_KEY, '+inf', $end, [
|
||||
'withscores' => true,
|
||||
'limit' => [0, $limit]
|
||||
]));
|
||||
}
|
||||
|
||||
public static function add($val)
|
||||
{
|
||||
if(self::count() > config('instance.timeline.network.cache_dropoff')) {
|
||||
if(config('database.redis.client') === 'phpredis') {
|
||||
Redis::zpopmin(self::CACHE_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
return Redis::zadd(self::CACHE_KEY, $val, $val);
|
||||
}
|
||||
|
||||
public static function rem($val)
|
||||
{
|
||||
return Redis::zrem(self::CACHE_KEY, $val);
|
||||
}
|
||||
|
||||
public static function del($val)
|
||||
{
|
||||
return self::rem($val);
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return Redis::zcard(self::CACHE_KEY);
|
||||
}
|
||||
|
||||
public static function warmCache($force = false, $limit = 100)
|
||||
{
|
||||
if(self::count() == 0 || $force == true) {
|
||||
Redis::del(self::CACHE_KEY);
|
||||
$ids = Status::whereNotNull('uri')
|
||||
->whereScope('public')
|
||||
->whereNull('in_reply_to_id')
|
||||
->whereNull('reblog_of_id')
|
||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||
->where('created_at', '>', now()->subHours(config('instance.timeline.network.max_hours_old')))
|
||||
->orderByDesc('created_at')
|
||||
->limit($limit)
|
||||
->pluck('id');
|
||||
foreach($ids as $id) {
|
||||
self::add($id);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformer\ActivityPub\Verb;
|
||||
|
||||
use App\FollowRequest;
|
||||
use League\Fractal;
|
||||
|
||||
class AcceptFollow extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(FollowRequest $follow)
|
||||
{
|
||||
return [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'type' => 'Accept',
|
||||
'id' => $follow->permalink(),
|
||||
'actor' => $follow->target->permalink(),
|
||||
'object' => [
|
||||
'type' => 'Follow',
|
||||
'id' => $follow->activity && isset($follow->activity['id']) ? $follow->activity['id'] : null,
|
||||
'actor' => $follow->actor->permalink(),
|
||||
'object' => $follow->target->permalink()
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformer\ActivityPub\Verb;
|
||||
|
||||
use App\FollowRequest;
|
||||
use League\Fractal;
|
||||
|
||||
class RejectFollow extends Fractal\TransformerAbstract
|
||||
{
|
||||
public function transform(FollowRequest $follow)
|
||||
{
|
||||
return [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'type' => 'Reject',
|
||||
'id' => $follow->permalink(null, '#rejects'),
|
||||
'actor' => $follow->target->permalink(),
|
||||
'object' => [
|
||||
'type' => 'Follow',
|
||||
'id' => $follow->activity && isset($follow->activity['id']) ? $follow->activity['id'] : null,
|
||||
'actor' => $follow->actor->permalink(),
|
||||
'object' => $follow->target->permalink()
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddObjectColumnToFollowRequestsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('follow_requests', function (Blueprint $table) {
|
||||
$table->json('activity')->nullable()->after('following_id');
|
||||
$table->timestamp('handled_at')->nullable()->after('is_local');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('follow_requests', function (Blueprint $table) {
|
||||
$table->dropColumn('activity');
|
||||
$table->dropColumn('handled_at');
|
||||
});
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
(()=>{"use strict";var e,o,t,r={},s={};function a(e){var o=s[e];if(void 0!==o)return o.exports;var t=s[e]={id:e,loaded:!1,exports:{}};return r[e].call(t.exports,t,t.exports,a),t.loaded=!0,t.exports}a.m=r,e=[],a.O=(o,t,r,s)=>{if(!t){var n=1/0;for(j=0;j<e.length;j++){for(var[t,r,s]=e[j],d=!0,i=0;i<t.length;i++)(!1&s||n>=s)&&Object.keys(a.O).every((e=>a.O[e](t[i])))?t.splice(i--,1):(d=!1,s<n&&(n=s));if(d){e.splice(j--,1);var l=r();void 0!==l&&(o=l)}}return o}s=s||0;for(var j=e.length;j>0&&e[j-1][2]>s;j--)e[j]=e[j-1];e[j]=[t,r,s]},a.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return a.d(o,{a:o}),o},a.d=(e,o)=>{for(var t in o)a.o(o,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce(((o,t)=>(a.f[t](e,o),o)),[])),a.u=e=>319===e?"js/home-ojtjadoml.js":500===e?"js/compose-ojtjadoml.js":132===e?"js/post-ojtjadoml.js":620===e?"js/profile-ojtjadoml.js":566===e?"js/dmym-ojtjadoml.js":935===e?"js/dmyh-ojtjadoml.js":97===e?"js/daci-ojtjadoml.js":340===e?"js/dffc-ojtjadoml.js":575===e?"js/dsfc-ojtjadoml.js":545===e?"js/dssc-ojtjadoml.js":417===e?"js/discover-ojtjadoml.js":863===e?"js/notifications-ojtjadoml.js":888===e?"js/dms-ojtjadoml.js":43===e?"js/dmsg-ojtjadoml.js":void 0,a.miniCssF=e=>({138:"css/spa",170:"css/app",242:"css/appdark",703:"css/admin",994:"css/landing"}[e]+".css"),a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),o={},t="pixelfed:",a.l=(e,r,s,n)=>{if(o[e])o[e].push(r);else{var d,i;if(void 0!==s)for(var l=document.getElementsByTagName("script"),j=0;j<l.length;j++){var c=l[j];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")==t+s){d=c;break}}d||(i=!0,(d=document.createElement("script")).charset="utf-8",d.timeout=120,a.nc&&d.setAttribute("nonce",a.nc),d.setAttribute("data-webpack",t+s),d.src=e),o[e]=[r];var u=(t,r)=>{d.onerror=d.onload=null,clearTimeout(f);var s=o[e];if(delete o[e],d.parentNode&&d.parentNode.removeChild(d),s&&s.forEach((e=>e(r))),t)return t(r)},f=setTimeout(u.bind(null,void 0,{type:"timeout",target:d}),12e4);d.onerror=u.bind(null,d.onerror),d.onload=u.bind(null,d.onload),i&&document.head.appendChild(d)}},a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),a.p="/",(()=>{var e={929:0,242:0,170:0,138:0,703:0,994:0};a.f.j=(o,t)=>{var r=a.o(e,o)?e[o]:void 0;if(0!==r)if(r)t.push(r[2]);else if(/^(138|170|242|703|929|994)$/.test(o))e[o]=0;else{var s=new Promise(((t,s)=>r=e[o]=[t,s]));t.push(r[2]=s);var n=a.p+a.u(o),d=new Error;a.l(n,(t=>{if(a.o(e,o)&&(0!==(r=e[o])&&(e[o]=void 0),r)){var s=t&&("load"===t.type?"missing":t.type),n=t&&t.target&&t.target.src;d.message="Loading chunk "+o+" failed.\n("+s+": "+n+")",d.name="ChunkLoadError",d.type=s,d.request=n,r[1](d)}}),"chunk-"+o,o)}},a.O.j=o=>0===e[o];var o=(o,t)=>{var r,s,[n,d,i]=t,l=0;if(n.some((o=>0!==e[o]))){for(r in d)a.o(d,r)&&(a.m[r]=d[r]);if(i)var j=i(a)}for(o&&o(t);l<n.length;l++)s=n[l],a.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return a.O(j)},t=self.webpackChunkpixelfed=self.webpackChunkpixelfed||[];t.forEach(o.bind(null,0)),t.push=o.bind(null,t.push.bind(t))})()})();
|
||||
(()=>{"use strict";var e,o,t,r={},s={};function a(e){var o=s[e];if(void 0!==o)return o.exports;var t=s[e]={id:e,loaded:!1,exports:{}};return r[e].call(t.exports,t,t.exports,a),t.loaded=!0,t.exports}a.m=r,e=[],a.O=(o,t,r,s)=>{if(!t){var n=1/0;for(j=0;j<e.length;j++){for(var[t,r,s]=e[j],d=!0,i=0;i<t.length;i++)(!1&s||n>=s)&&Object.keys(a.O).every((e=>a.O[e](t[i])))?t.splice(i--,1):(d=!1,s<n&&(n=s));if(d){e.splice(j--,1);var l=r();void 0!==l&&(o=l)}}return o}s=s||0;for(var j=e.length;j>0&&e[j-1][2]>s;j--)e[j]=e[j-1];e[j]=[t,r,s]},a.n=e=>{var o=e&&e.__esModule?()=>e.default:()=>e;return a.d(o,{a:o}),o},a.d=(e,o)=>{for(var t in o)a.o(o,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce(((o,t)=>(a.f[t](e,o),o)),[])),a.u=e=>319===e?"js/home-ojtjadoml.js":500===e?"js/compose-ojtjadoml.js":132===e?"js/post-ojtjadoml.js":620===e?"js/profile-ojtjadoml.js":566===e?"js/dmym-ojtjadoml.js":935===e?"js/dmyh-ojtjadoml.js":97===e?"js/daci-ojtjadoml.js":340===e?"js/dffc-ojtjadoml.js":575===e?"js/dsfc-ojtjadoml.js":545===e?"js/dssc-ojtjadoml.js":417===e?"js/discover-ojtjadoml.js":863===e?"js/notifications-ojtjadoml.js":888===e?"js/dms-ojtjadoml.js":43===e?"js/dmsg-ojtjadoml.js":void 0,a.miniCssF=e=>({138:"css/spa",170:"css/app",242:"css/appdark",703:"css/admin",994:"css/landing"}[e]+".css"),a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),o={},t="pixelfed:",a.l=(e,r,s,n)=>{if(o[e])o[e].push(r);else{var d,i;if(void 0!==s)for(var l=document.getElementsByTagName("script"),j=0;j<l.length;j++){var c=l[j];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")==t+s){d=c;break}}d||(i=!0,(d=document.createElement("script")).charset="utf-8",d.timeout=120,a.nc&&d.setAttribute("nonce",a.nc),d.setAttribute("data-webpack",t+s),d.src=e),o[e]=[r];var u=(t,r)=>{d.onerror=d.onload=null,clearTimeout(f);var s=o[e];if(delete o[e],d.parentNode&&d.parentNode.removeChild(d),s&&s.forEach((e=>e(r))),t)return t(r)},f=setTimeout(u.bind(null,void 0,{type:"timeout",target:d}),12e4);d.onerror=u.bind(null,d.onerror),d.onload=u.bind(null,d.onload),i&&document.head.appendChild(d)}},a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),a.p="/",(()=>{var e={929:0,242:0,170:0,138:0,703:0,994:0};a.f.j=(o,t)=>{var r=a.o(e,o)?e[o]:void 0;if(0!==r)if(r)t.push(r[2]);else if(/^(138|170|242|703|929|994)$/.test(o))e[o]=0;else{var s=new Promise(((t,s)=>r=e[o]=[t,s]));t.push(r[2]=s);var n=a.p+a.u(o),d=new Error;a.l(n,(t=>{if(a.o(e,o)&&(0!==(r=e[o])&&(e[o]=void 0),r)){var s=t&&("load"===t.type?"missing":t.type),n=t&&t.target&&t.target.src;d.message="Loading chunk "+o+" failed.\n("+s+": "+n+")",d.name="ChunkLoadError",d.type=s,d.request=n,r[1](d)}}),"chunk-"+o,o)}},a.O.j=o=>0===e[o];var o=(o,t)=>{var r,s,[n,d,i]=t,l=0;if(n.some((o=>0!==e[o]))){for(r in d)a.o(d,r)&&(a.m[r]=d[r]);if(i)var j=i(a)}for(o&&o(t);l<n.length;l++)s=n[l],a.o(e,s)&&e[s]&&e[s][0](),e[s]=0;return a.O(j)},t=self.webpackChunkpixelfed=self.webpackChunkpixelfed||[];t.forEach(o.bind(null,0)),t.push=o.bind(null,t.push.bind(t))})(),a.nc=void 0})();
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue