kopia lustrzana https://github.com/pixelfed/pixelfed
Porównaj commity
467 Commity
Autor | SHA1 | Data |
---|---|---|
daniel | ab383ba55b | |
Daniel Supernault | 29e472d6ca | |
Daniel Supernault | 9a5e3471d4 | |
Daniel Supernault | 61d105fd25 | |
daniel | 101e620bf5 | |
Daniel Supernault | 2d3f1df003 | |
Daniel Supernault | 7c19baf5dc | |
Daniel Supernault | 326bb93b8b | |
daniel | 64631c7233 | |
Daniel Supernault | 902572ed51 | |
Daniel Supernault | 60a62b59c9 | |
daniel | 3e59dd2868 | |
Daniel Supernault | cbf996c9b6 | |
daniel | cf10fca74f | |
Daniel Supernault | aa94dde376 | |
daniel | eecc7bef61 | |
Daniel Supernault | 3c877523b1 | |
Daniel Supernault | 4223119f58 | |
daniel | 74a3d5c6c0 | |
Daniel Supernault | 7f8bba4415 | |
daniel | 6263e90a13 | |
Daniel Supernault | e46bd6cc06 | |
daniel | ae60c99679 | |
Daniel Supernault | a54b4fb038 | |
daniel | 2f7481205c | |
Daniel Supernault | cde17f5af7 | |
Daniel Supernault | 433bc4c286 | |
daniel | 5d407ededf | |
Daniel Supernault | 65166570c5 | |
daniel | 610326e7b0 | |
Daniel Supernault | 6fc066a213 | |
Daniel Supernault | 8b8b1ffc5c | |
Daniel Supernault | 9a7acc12a6 | |
Daniel Supernault | 51b6fe7dc8 | |
daniel | c4ffa62242 | |
Daniel Supernault | 87ee0633fe | |
Daniel Supernault | ded660b2c4 | |
daniel | 4d04227d41 | |
Daniel Supernault | 26f92c93ce | |
Daniel Supernault | 81566987e4 | |
Daniel Supernault | 8af2360779 | |
daniel | b3fb69c5b1 | |
Daniel Supernault | f30f7d79fb | |
Daniel Supernault | 2deb65d874 | |
Daniel Supernault | ad03291699 | |
daniel | 6be21891d5 | |
daniel | 141f6d38a7 | |
Daniel Supernault | 4608c66c0b | |
Christian Winther | e227ee1bd5 | |
Christian Winther | dbc5df849f | |
Daniel Supernault | 6bdf73de4d | |
daniel | 5b3d0206ae | |
Daniel Supernault | 858fcbf606 | |
daniel | 57df06a0b6 | |
Daniel Supernault | db1a4c9f8e | |
Daniel Supernault | ce4beab9c8 | |
Daniel Supernault | 9d5479de39 | |
Daniel Supernault | 512518d319 | |
Daniel Supernault | b06a3455c2 | |
Daniel Supernault | 94a6e8614a | |
Daniel Supernault | 81d1e0fdab | |
Daniel Supernault | b8e96a5ff3 | |
Daniel Supernault | b7322b6874 | |
daniel | 142db2c41e | |
Daniel Supernault | 8c6936409d | |
daniel | e2c2952fda | |
daniel | dfab7e945a | |
daniel | 363196883d | |
daniel | f1eaaa80be | |
daniel | 0b162dc15e | |
Daniel Supernault | a9e54aa540 | |
Daniel Supernault | 3871a80391 | |
Daniel Supernault | 4147f7c521 | |
Daniel Supernault | 039dfaa6c3 | |
Daniel Supernault | f318bd7a30 | |
Daniel Supernault | d946afcc5c | |
Daniel Supernault | 2dcbc1d5ef | |
Daniel Supernault | ec2fdd61f7 | |
Daniel Supernault | aba1e13d43 | |
Daniel Supernault | dcc5f416ef | |
Emelia Smith | 1eadff9d2e | |
Daniel Supernault | ac1f074889 | |
Daniel Supernault | 5162c0704a | |
Daniel Supernault | 3628b4625c | |
Daniel Supernault | 674e560f04 | |
Daniel Supernault | eb4871237b | |
Daniel Supernault | 704e7b12e0 | |
Daniel Supernault | cee979eda8 | |
Daniel Supernault | 828a456f36 | |
Daniel Supernault | 087b27916f | |
Daniel Supernault | 6ce513f8c3 | |
Daniel Supernault | 949e99798e | |
Daniel Supernault | 911446c03e | |
Daniel Supernault | a76cb5f4f8 | |
Daniel Supernault | da0e0ffabf | |
Daniel Supernault | 2d113de536 | |
Daniel Supernault | d1adb109de | |
Daniel Supernault | ce228f7fa4 | |
Daniel Supernault | 5071aaf408 | |
Daniel Supernault | 40478f258a | |
Daniel Supernault | d670de175e | |
Daniel Supernault | fecbe1897b | |
Daniel Supernault | 665581d80c | |
Daniel Supernault | a72188a7db | |
Daniel Supernault | ad506e901d | |
Daniel Supernault | f2f2a8097c | |
Daniel Supernault | f08aab2231 | |
Daniel Supernault | 8a0c456edc | |
Daniel Supernault | 75081e609a | |
Daniel Supernault | 481314cd23 | |
Daniel Supernault | 8a89e3c963 | |
Daniel Supernault | c96167f2f7 | |
Christian Winther | ad382f8f55 | |
Christian Winther | 3a1f4789e6 | |
Christian Winther | 4942f7fbd4 | |
Christian Winther | cc8c5ccd37 | |
Christian Winther | 56d47dd1bc | |
Christian Winther | 1892f68ebd | |
Christian Winther | ca7c2d34f2 | |
daniel | 8aae92d75b | |
Daniel Supernault | bf46f6f5f4 | |
Daniel Supernault | b0cb4456a9 | |
Daniel Supernault | 7785a2dae4 | |
daniel | 57f4457637 | |
Daniel Supernault | 5e4d4eff9d | |
daniel | 3132523798 | |
Daniel Supernault | a4bc5ce3d0 | |
daniel | f4086d4381 | |
Daniel Supernault | 37a82cfb90 | |
Daniel Supernault | 4aa0e25f4c | |
daniel | 24c467c558 | |
Daniel Supernault | bcce1df6fc | |
Daniel Supernault | a969ca502f | |
Daniel Supernault | 36c518fe2c | |
Daniel Supernault | 95199843e3 | |
Daniel Supernault | 853a729f76 | |
Daniel Supernault | e742d595a6 | |
Daniel Supernault | 2e5e68e447 | |
Daniel Supernault | 63100fe950 | |
Daniel Supernault | 25f3fa06af | |
daniel | f09313a512 | |
Daniel Supernault | 15ad69f76e | |
Christian Winther | 091de696c2 | |
daniel | 7c2ecd8706 | |
Daniel Supernault | b89cd4c44f | |
Daniel Supernault | cee618e844 | |
daniel | 4516760ced | |
Daniel Supernault | 94503a1cf9 | |
daniel | 5d7e091978 | |
Daniel Supernault | 18382e8a1f | |
Daniel Supernault | 592c84125c | |
daniel | b6437380b4 | |
Daniel Supernault | e68fe64ffc | |
Daniel Supernault | 3a27e637f8 | |
Christian Winther | dd5878b256 | |
Christian Winther | ae645ddd15 | |
Christian Winther | e38aa65dad | |
daniel | 0355830c5c | |
Daniel Supernault | eccdbe1f57 | |
Daniel Supernault | 632f2cb619 | |
daniel | 23f7b74400 | |
Daniel Supernault | b1cdf4464f | |
Daniel Supernault | b122c60de7 | |
Daniel Supernault | 6036d96e3f | |
Daniel Supernault | ff150ca6c9 | |
daniel | fc8462d565 | |
Daniel Supernault | 6231994253 | |
daniel | 5d21bba7b5 | |
Daniel Supernault | d18824e719 | |
Daniel Supernault | d3f6c71b8e | |
daniel | 0bd3e0ab80 | |
Daniel Supernault | 5fb26a78bc | |
daniel | 1251bf532c | |
Daniel Supernault | 03165ea46f | |
Daniel Supernault | 3b5500b3a5 | |
Daniel Supernault | 1a811b1840 | |
Daniel Supernault | e3826c587d | |
Daniel Supernault | d6eac65555 | |
daniel | eb19c35343 | |
Daniel Supernault | 6cb1484b3e | |
Daniel Supernault | 01535a6cfe | |
Daniel Supernault | 31e6487dc9 | |
Daniel Supernault | a933615b8d | |
daniel | a9b99d8f9d | |
Daniel Supernault | 3f0539978e | |
daniel | 712b6d27a9 | |
Daniel Supernault | 4a6be62128 | |
Daniel Supernault | 45bdfe1efd | |
Shlee | 7fd5599fc4 | |
Daniel Supernault | 7613eec476 | |
Daniel Supernault | 9bc5338dbd | |
Daniel Supernault | f8145a78cf | |
Christian Winther | d92cf7f92f | |
daniel | 99611f90ea | |
Daniel Supernault | d5a6d9cc8d | |
Daniel Supernault | 542d110673 | |
Daniel Supernault | 402a4607c9 | |
Christian Winther | 5d56460082 | |
daniel | 189e87f28a | |
Daniel Supernault | c4190eec08 | |
Daniel Supernault | 0bb7d379c5 | |
Daniel Supernault | 372a116a2c | |
Daniel Supernault | ef0ff78e4a | |
Daniel Supernault | ab9ecb6efd | |
daniel | e4f33e823d | |
Daniel Supernault | 2f48df8ca8 | |
Christian Winther | 6fa112162f | |
Daniel Supernault | a16309ac18 | |
Daniel Supernault | 767522a85c | |
daniel | 8c1e136ce9 | |
Daniel Supernault | 071163b47b | |
Christian Winther | acb699bf13 | |
Christian Winther | 02369cce66 | |
Christian Winther | c1c361ef9b | |
Christian Winther | b08bb3669d | |
Christian Winther | 1976af6dd1 | |
Christian Winther | 020bda85db | |
daniel | 507f45f139 | |
Daniel Supernault | 795e91e3bc | |
Daniel Supernault | 2b5d723582 | |
daniel | 7159d5cb3e | |
Daniel Supernault | 84aeec3b4e | |
Daniel Supernault | 089ba3c471 | |
Christian Winther | df1f62e734 | |
Christian Winther | c8c2e1c2eb | |
Christian Winther | 2d8e81c83f | |
Christian Winther | 515198b28c | |
Christian Winther | f0e30c8ab6 | |
Christian Winther | 7ffbd5d44a | |
Christian Winther | 5a43d7a65d | |
Christian Winther | 027f858d85 | |
Christian Winther | e2821adcca | |
Christian Winther | af47d91e7d | |
Christian Winther | 193d536ca1 | |
Christian Winther | f264dd1cbb | |
Christian Winther | d9d2a475d8 | |
Christian Winther | 8fd27c6f0c | |
Christian Winther | 0addfe5605 | |
Christian Winther | 28b83b575f | |
Christian Winther | 3bfd043792 | |
Christian Winther | 0ecebbb8bf | |
Christian Winther | 9c26bf26dd | |
Christian Winther | ae358e47cb | |
Christian Winther | 14f8478e6a | |
Christian Winther | 26d6f8f9fe | |
daniel | 36f84db03b | |
Daniel Supernault | eadf2e9d1d | |
Daniel Supernault | b0ecdc8162 | |
Daniel Supernault | 59c70239f8 | |
daniel | b2f29a4590 | |
Daniel Supernault | 4c5e8288b0 | |
Daniel Supernault | c4dde64119 | |
Christian Winther | f486bfb73e | |
Christian Winther | adf1af3703 | |
Christian Winther | abee7d4d62 | |
Christian Winther | 5a9cfe1f2a | |
daniel | 1f6dc94a34 | |
Daniel Supernault | e1715d40b8 | |
Daniel Supernault | 0ad3654da3 | |
Daniel Supernault | 06655c3a8b | |
Daniel Supernault | cae26c666d | |
Daniel Supernault | 8355d5d00c | |
Daniel Supernault | 8dac2caf1d | |
daniel | 4057ee3bb3 | |
Daniel Supernault | 9409c569bd | |
Daniel Supernault | b6c97d1d26 | |
Daniel Supernault | eb0e76f8e2 | |
Daniel Supernault | 1f74a95d0c | |
daniel | 6c0c61e45a | |
daniel | 8cb7ebdd8b | |
Daniel Supernault | ce9c0e0b24 | |
Daniel Supernault | 545f7d5e70 | |
daniel | f97afcf47e | |
daniel | b339f4a5b0 | |
Daniel Supernault | 147113cc95 | |
Daniel Supernault | ea6b162340 | |
Daniel Supernault | 4c26f59cd0 | |
Christian Winther | 9117df186c | |
Christian Winther | 4dc15bb37d | |
daniel | 4eb0c36480 | |
Daniel Supernault | 17027c3487 | |
Daniel Supernault | 011834f473 | |
Christian Winther | 9a1c4d42b5 | |
Christian Winther | 6edd712581 | |
Christian Winther | d4198b3262 | |
Emelia Smith | 9978b2b959 | |
daniel | 01a86009e6 | |
Daniel Supernault | d835e0adaa | |
daniel | f45d293707 | |
Daniel Supernault | 66f6640072 | |
daniel | 25dd2e46fe | |
Daniel Supernault | f07843a0f2 | |
Daniel Supernault | 56b736c325 | |
Daniel Supernault | b0fb198829 | |
daniel | e1d579b10b | |
Daniel Supernault | 83eadbb811 | |
Daniel Supernault | 40b45b2a11 | |
daniel | ccbba91e70 | |
Daniel Supernault | bc4d223714 | |
daniel | 0032415459 | |
Daniel Supernault | 70fc44dfe5 | |
Daniel Supernault | 0f3ca19461 | |
daniel | 0dc54e9ac0 | |
Daniel Supernault | df5e61266c | |
Daniel Supernault | 1232cfc86a | |
daniel | af935c729b | |
Daniel Supernault | 4c6ec20e36 | |
Daniel Supernault | fb0bb9a34f | |
Christian Winther | d3bbfdb6e0 | |
daniel | b10c60584b | |
Daniel Supernault | 221fe43638 | |
Daniel Supernault | 97c131fdf2 | |
Daniel Supernault | 78da12004f | |
Daniel Supernault | 8b4ac5cc0b | |
daniel | bbd3688333 | |
Daniel Supernault | 7b8977e9cc | |
Daniel Supernault | 0faf59e3b7 | |
Christian Winther | 49a778d128 | |
Christian Winther | fd62962d20 | |
Christian Winther | e18d6083a2 | |
Christian Winther | 143d5703dd | |
Christian Winther | bc66b6da18 | |
Christian Winther | d8e1caec53 | |
Christian Winther | d9a9507cc8 | |
Christian Winther | 5bd93b0f5e | |
Christian Winther | 3d6efd098d | |
Christian Winther | d374d73ba7 | |
mbliznikova | fd4f41a14e | |
Christian Winther | 2aeccf885f | |
Christian Winther | 043f914c8c | |
Christian Winther | 3723f36043 | |
Christian Winther | ef37c8f234 | |
Christian Winther | b73d452255 | |
Christian Winther | 36850235a8 | |
Christian Winther | 1a6e97c98b | |
Christian Winther | 8bdb0ca77b | |
Christian Winther | c4f984b205 | |
Christian Winther | 1616c7cb11 | |
Christian Winther | ca5710b5ae | |
Christian Winther | a665168031 | |
Christian Winther | 335e6954d2 | |
Christian Winther | 5c208d0519 | |
Christian Winther | aa2669c327 | |
Christian Winther | 8189b01a26 | |
Christian Winther | d372b9dee7 | |
Christian Winther | d2ed117d3f | |
Christian Winther | 8d61b8d250 | |
Christian Winther | c859367e10 | |
Christian Winther | 6fee842b7a | |
Christian Winther | 627fffd1ce | |
Christian Winther | f263dfc4e1 | |
Christian Winther | c9a3e3aea7 | |
Christian Winther | 8672453596 | |
Christian Winther | 347ac6f82b | |
Christian Winther | 70f4bc06a8 | |
Christian Winther | a940bedf9e | |
Christian Winther | 2d223d61ed | |
Christian Winther | f2b28ece6e | |
Christian Winther | 3598f9f8f4 | |
Christian Winther | 29564a5809 | |
Christian Winther | 033db841f4 | |
Christian Winther | a383233710 | |
Christian Winther | 32ad4266d0 | |
Christian Winther | 1500791198 | |
Christian Winther | e858a453be | |
Christian Winther | 4729ffb7d5 | |
Christian Winther | 83d92c4819 | |
Christian Winther | eba2db76f2 | |
Christian Winther | a3fd373796 | |
Christian Winther | 98bae1316f | |
Christian Winther | 068143639f | |
Christian Winther | f135a240cd | |
Christian Winther | a094a0bd66 | |
Christian Winther | dc95d4d800 | |
Christian Winther | ca0a25912a | |
Christian Winther | 62efe8b3d4 | |
Christian Winther | ead7c33275 | |
Christian Winther | cc9f673eea | |
Christian Winther | 921f34d42e | |
Christian Winther | 82ab545f1a | |
Christian Winther | eee17fe9f2 | |
Christian Winther | adbd66eb38 | |
Christian Winther | 3feb93b034 | |
Christian Winther | a4646df8f2 | |
Christian Winther | 2d05eccb87 | |
Christian Winther | e70e13e265 | |
Christian Winther | 90c9d8b5a6 | |
Christian Winther | 9ad04a285a | |
Christian Winther | 3a7fd8eac9 | |
Christian Winther | 45f1df78b0 | |
Christian Winther | 44266b950b | |
Christian Winther | be2ba79dc2 | |
Christian Winther | d8b37e6870 | |
Christian Winther | 6563d4d0b9 | |
Christian Winther | afa335b7b5 | |
Christian Winther | a70f108616 | |
Christian Winther | bb960fd485 | |
Christian Winther | 88ad5d6a4f | |
Christian Winther | 24220ef2a8 | |
Christian Winther | daba285ea7 | |
Christian Winther | de96c5f06d | |
Christian Winther | 72b454143b | |
Christian Winther | af1df5edfd | |
Christian Winther | 2135199c97 | |
Christian Winther | 9c426b48a1 | |
Christian Winther | 48e5d45b3f | |
Christian Winther | 98660760c9 | |
Christian Winther | 53eb9c11fc | |
Christian Winther | 903aeb7608 | |
Christian Winther | 685f62a5d0 | |
Christian Winther | 7f99bb1024 | |
Christian Winther | fa10fe999e | |
Christian Winther | b2d6d3dbe7 | |
Christian Winther | f2f2517503 | |
Christian Winther | ed0f9d64c8 | |
Christian Winther | 901d11df60 | |
Christian Winther | 20ef1c7b94 | |
Christian Winther | 20a15c2b65 | |
Christian Winther | 01ecde1592 | |
Christian Winther | 9814a39fd8 | |
Christian Winther | 519704cbe8 | |
Christian Winther | 543dac34f6 | |
Christian Winther | edbc1e4d60 | |
Christian Winther | c258a15761 | |
Christian Winther | 84c9aeb514 | |
Christian Winther | 73b6db168a | |
Christian Winther | 6f0a6aeb3d | |
Christian Winther | 2e3c7e862c | |
Christian Winther | 284bb26d92 | |
Christian Winther | 9445980e04 | |
Christian Winther | bd1cd9c4fc | |
Christian Winther | e228a1622d | |
Christian Winther | c9b11a4a29 | |
Christian Winther | 092f7f704c | |
Christian Winther | 6edf266a14 | |
Christian Winther | a8c5585e19 | |
Christian Winther | a25b7910b2 | |
Christian Winther | 7db513b366 | |
Christian Winther | 76e1199dc7 | |
Christian Winther | 2e2ffc5519 | |
Christian Winther | d876533991 | |
Christian Winther | c4404590f2 | |
Christian Winther | c1fbccb07c | |
Christian Winther | 052c11882c | |
Christian Winther | 215b49ea3d | |
Christian Winther | 10674ac523 | |
Christian Winther | f2eb3df85f | |
Christian Winther | 5cfd8e15a9 | |
Christian Winther | 99e2a045a6 | |
Christian Winther | d13895a3e0 | |
Christian Winther | 895b51fd9f | |
Christian Winther | 890827d60e | |
Christian Winther | c12ef66c56 | |
Christian Winther | c64571e46d | |
Christian Winther | f2c8497136 | |
Christian Winther | ce34e4d046 | |
Christian Winther | a08a5e7cde | |
Christian Winther | e05575283a | |
Christian Winther | c369ef50a7 | |
Christian Winther | 7dcca09c65 | |
Christian Winther | 7b3e11012f | |
Christian Winther | 0aee66810d | |
Christian Winther | 6244511cf8 | |
Christian Winther | f390c3c3e9 | |
Christian Winther | cf080dda09 | |
Christian Winther | b19d3a20dd | |
Christian Winther | 98211d3620 |
|
@ -21,7 +21,12 @@ jobs:
|
|||
steps:
|
||||
- checkout
|
||||
|
||||
- run: sudo apt update && sudo apt install zlib1g-dev libsqlite3-dev
|
||||
- run:
|
||||
name: "Create Environment file and generate app key"
|
||||
command: |
|
||||
mv .env.testing .env
|
||||
|
||||
- run: sudo apt install zlib1g-dev libsqlite3-dev
|
||||
|
||||
# Download and cache dependencies
|
||||
|
||||
|
@ -36,18 +41,17 @@ jobs:
|
|||
- run: composer install -n --prefer-dist
|
||||
|
||||
- save_cache:
|
||||
key: composer-v2-{{ checksum "composer.lock" }}
|
||||
key: v2-dependencies-{{ checksum "composer.json" }}
|
||||
paths:
|
||||
- vendor
|
||||
|
||||
- run: cp .env.testing .env
|
||||
- run: php artisan config:cache
|
||||
- run: php artisan route:clear
|
||||
- run: php artisan storage:link
|
||||
- run: php artisan key:generate
|
||||
|
||||
# run tests with phpunit or codecept
|
||||
- run: ./vendor/bin/phpunit
|
||||
- run: php artisan test
|
||||
- store_test_results:
|
||||
path: tests/_output
|
||||
- store_artifacts:
|
||||
|
|
|
@ -4,4 +4,4 @@
|
|||
## Usage: redis-cli [flags] [args]
|
||||
## Example: "redis-cli KEYS *" or "ddev redis-cli INFO" or "ddev redis-cli --version"
|
||||
|
||||
redis-cli -p 6379 -h redis $@
|
||||
exec redis-cli -p 6379 -h redis "$@"
|
||||
|
|
|
@ -1,8 +1,30 @@
|
|||
data
|
||||
Dockerfile
|
||||
contrib/docker/Dockerfile.*
|
||||
docker-compose*.yml
|
||||
.dockerignore
|
||||
.git
|
||||
.gitignore
|
||||
.env
|
||||
.DS_Store
|
||||
/.bash_history
|
||||
/.bash_profile
|
||||
/.bashrc
|
||||
/.composer
|
||||
/.env
|
||||
/.env.dottie-backup
|
||||
/.git
|
||||
/.git-credentials
|
||||
/.gitconfig
|
||||
/.gitignore
|
||||
/.idea
|
||||
/.vagrant
|
||||
/bootstrap/cache
|
||||
/docker-compose-state/
|
||||
/Homestead.json
|
||||
/Homestead.yaml
|
||||
/node_modules
|
||||
/npm-debug.log
|
||||
/public/hot
|
||||
/public/storage
|
||||
/public/vendor/horizon
|
||||
/storage/*.key
|
||||
/storage/docker
|
||||
/vendor
|
||||
/yarn-error.log
|
||||
|
||||
# Exceptions - these *MUST* be last
|
||||
!/bootstrap/cache/.gitignore
|
||||
!/public/vendor/horizon/.gitignore
|
||||
|
|
|
@ -7,3 +7,21 @@ end_of_line = lf
|
|||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{sh,envsh,env,env*}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# ShellCheck config
|
||||
shell_variant = bash # like -ln=bash
|
||||
binary_next_line = true # like -bn
|
||||
switch_case_indent = true # like -ci
|
||||
space_redirects = false # like -sr
|
||||
keep_padding = false # like -kp
|
||||
function_next_line = true # like -fn
|
||||
never_split = true # like -ns
|
||||
simplify = true
|
||||
|
|
1392
.env.docker
1392
.env.docker
Plik diff jest za duży
Load Diff
|
@ -8,6 +8,7 @@ OPEN_REGISTRATION="false"
|
|||
ENFORCE_EMAIL_VERIFICATION="false"
|
||||
PF_MAX_USERS="1000"
|
||||
OAUTH_ENABLED="true"
|
||||
ENABLE_CONFIG_CACHE=true
|
||||
|
||||
# Media Configuration
|
||||
PF_OPTIMIZE_IMAGES="true"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# shellcheck disable=SC2034,SC2148
|
||||
|
||||
APP_NAME="Pixelfed Test"
|
||||
APP_ENV=local
|
||||
APP_KEY=base64:lwX95GbNWX3XsucdMe0XwtOKECta3h/B+p9NbH2jd0E=
|
||||
|
@ -62,8 +64,8 @@ CS_BLOCKED_DOMAINS='example.org,example.net,example.com'
|
|||
CS_CW_DOMAINS='example.org,example.net,example.com'
|
||||
CS_UNLISTED_DOMAINS='example.org,example.net,example.com'
|
||||
|
||||
## Optional
|
||||
## Optional
|
||||
#HORIZON_DARKMODE=false # Horizon theme darkmode
|
||||
#HORIZON_EMBED=false # Single Docker Container mode
|
||||
#HORIZON_EMBED=false # Single Docker Container mode
|
||||
|
||||
ENABLE_CONFIG_CACHE=false
|
||||
|
|
|
@ -3,3 +3,10 @@
|
|||
*.scss linguist-vendored
|
||||
*.js linguist-vendored
|
||||
CHANGELOG.md export-ignore
|
||||
|
||||
# Collapse diffs for generated files:
|
||||
public/**/*.js text -diff
|
||||
public/**/*.json text -diff
|
||||
public/**/*.css text -diff
|
||||
public/img/* binary -diff
|
||||
public/fonts/* binary -diff
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
---
|
||||
name: Build Docker image
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
tags:
|
||||
- '*'
|
||||
pull_request:
|
||||
paths:
|
||||
- .github/workflows/build-docker.yml
|
||||
- contrib/docker/Dockerfile.apache
|
||||
- contrib/docker/Dockerfile.fpm
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build-docker-apache:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Docker Lint
|
||||
uses: hadolint/hadolint-action@v3.0.0
|
||||
with:
|
||||
dockerfile: contrib/docker/Dockerfile.apache
|
||||
failure-threshold: error
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
secrets: inherit
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
- name: Fetch tags
|
||||
uses: docker/metadata-action@v4
|
||||
secrets: inherit
|
||||
id: meta
|
||||
with:
|
||||
images: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed
|
||||
flavor: |
|
||||
latest=auto
|
||||
suffix=-apache
|
||||
tags: |
|
||||
type=edge,branch=dev
|
||||
type=pep440,pattern={{raw}}
|
||||
type=pep440,pattern=v{{major}}.{{minor}}
|
||||
type=ref,event=pr
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
file: contrib/docker/Dockerfile.apache
|
||||
platforms: linux/amd64,linux/arm64
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
build-docker-fpm:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Docker Lint
|
||||
uses: hadolint/hadolint-action@v3.0.0
|
||||
with:
|
||||
dockerfile: contrib/docker/Dockerfile.fpm
|
||||
failure-threshold: error
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
secrets: inherit
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
- name: Fetch tags
|
||||
uses: docker/metadata-action@v4
|
||||
secrets: inherit
|
||||
id: meta
|
||||
with:
|
||||
images: ${{ secrets.DOCKER_HUB_ORGANISATION }}/pixelfed
|
||||
flavor: |
|
||||
suffix=-fpm
|
||||
tags: |
|
||||
type=edge,branch=dev
|
||||
type=pep440,pattern={{raw}}
|
||||
type=pep440,pattern=v{{major}}.{{minor}}
|
||||
type=ref,event=pr
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
file: contrib/docker/Dockerfile.fpm
|
||||
platforms: linux/amd64,linux/arm64
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
|
@ -0,0 +1,230 @@
|
|||
---
|
||||
name: Docker
|
||||
|
||||
on:
|
||||
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
|
||||
workflow_dispatch:
|
||||
|
||||
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
- staging
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
# See: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- reopened
|
||||
- synchronize
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: hadolint
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Docker Lint
|
||||
uses: hadolint/hadolint-action@v3.1.0
|
||||
with:
|
||||
dockerfile: Dockerfile
|
||||
failure-threshold: error
|
||||
|
||||
shellcheck:
|
||||
name: ShellCheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
env:
|
||||
SHELLCHECK_OPTS: --shell=bash --external-sources
|
||||
with:
|
||||
version: v0.9.0
|
||||
additional_files: "*.envsh .env .env.docker .env.example .env.testing"
|
||||
|
||||
bats:
|
||||
name: Bats Testing
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run bats
|
||||
run: docker run -v "$PWD:/var/www" bats/bats:latest /var/www/tests/bats
|
||||
|
||||
build:
|
||||
name: Build, Test, and Push
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
||||
# See: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
|
||||
matrix:
|
||||
php_version:
|
||||
- 8.2
|
||||
- 8.3
|
||||
target_runtime:
|
||||
- apache
|
||||
- fpm
|
||||
- nginx
|
||||
php_base:
|
||||
- apache
|
||||
- fpm
|
||||
|
||||
# See: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#excluding-matrix-configurations
|
||||
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrixexclude
|
||||
exclude:
|
||||
# targeting [apache] runtime with [fpm] base type doesn't make sense
|
||||
- target_runtime: apache
|
||||
php_base: fpm
|
||||
|
||||
# targeting [fpm] runtime with [apache] base type doesn't make sense
|
||||
- target_runtime: fpm
|
||||
php_base: apache
|
||||
|
||||
# targeting [nginx] runtime with [apache] base type doesn't make sense
|
||||
- target_runtime: nginx
|
||||
php_base: apache
|
||||
|
||||
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-concurrency-and-the-default-behavior
|
||||
concurrency:
|
||||
group: docker-build-${{ github.ref }}-${{ matrix.php_base }}-${{ matrix.php_version }}-${{ matrix.target_runtime }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
env:
|
||||
# Set the repo variable [DOCKER_HUB_USERNAME] to override the default
|
||||
# at https://github.com/<user>/<project>/settings/variables/actions
|
||||
DOCKER_HUB_USERNAME: ${{ vars.DOCKER_HUB_USERNAME || 'pixelfed' }}
|
||||
|
||||
# Set the repo variable [DOCKER_HUB_ORGANISATION] to override the default
|
||||
# at https://github.com/<user>/<project>/settings/variables/actions
|
||||
DOCKER_HUB_ORGANISATION: ${{ vars.DOCKER_HUB_ORGANISATION || 'pixelfed' }}
|
||||
|
||||
# Set the repo variable [DOCKER_HUB_REPO] to override the default
|
||||
# at https://github.com/<user>/<project>/settings/variables/actions
|
||||
DOCKER_HUB_REPO: ${{ vars.DOCKER_HUB_REPO || 'pixelfed' }}
|
||||
|
||||
# For Docker Hub pushing to work, you need the secret [DOCKER_HUB_TOKEN]
|
||||
# set to your Personal Access Token at https://github.com/<user>/<project>/settings/secrets/actions
|
||||
#
|
||||
# ! NOTE: no [login] or [push] will happen to Docker Hub until this secret is set!
|
||||
HAS_DOCKER_HUB_CONFIGURED: ${{ secrets.DOCKER_HUB_TOKEN != '' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
id: buildx
|
||||
with:
|
||||
version: v0.12.0 # *or* newer, needed for annotations to work
|
||||
|
||||
# See: https://github.com/docker/login-action?tab=readme-ov-file#github-container-registry
|
||||
- name: Log in to the GitHub Container registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# See: https://github.com/docker/login-action?tab=readme-ov-file#docker-hub
|
||||
- name: Login to Docker Hub registry (conditionally)
|
||||
if: ${{ env.HAS_DOCKER_HUB_CONFIGURED == true }}
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ env.DOCKER_HUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
|
||||
- name: Docker meta
|
||||
uses: docker/metadata-action@v5
|
||||
id: meta
|
||||
with:
|
||||
images: |
|
||||
name=ghcr.io/${{ github.repository }},enable=true
|
||||
name=${{ env.DOCKER_HUB_ORGANISATION }}/${{ env.DOCKER_HUB_REPO }},enable=${{ env.HAS_DOCKER_HUB_CONFIGURED }}
|
||||
flavor: |
|
||||
latest=auto
|
||||
suffix=-${{ matrix.target_runtime }}-${{ matrix.php_version }}
|
||||
tags: |
|
||||
type=raw,value=dev,enable=${{ github.ref == format('refs/heads/{0}', 'dev') }}
|
||||
type=raw,value=staging,enable=${{ github.ref == format('refs/heads/{0}', 'staging') }}
|
||||
type=pep440,pattern={{raw}}
|
||||
type=pep440,pattern=v{{major}}.{{minor}}
|
||||
type=ref,event=branch,prefix=branch-
|
||||
type=ref,event=pr,prefix=pr-
|
||||
type=ref,event=tag
|
||||
env:
|
||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||
|
||||
- name: Docker meta (Cache)
|
||||
uses: docker/metadata-action@v5
|
||||
id: cache
|
||||
with:
|
||||
images: |
|
||||
name=ghcr.io/${{ github.repository }}-cache,enable=true
|
||||
name=${{ env.DOCKER_HUB_ORGANISATION }}/${{ env.DOCKER_HUB_REPO }}-cache,enable=${{ env.HAS_DOCKER_HUB_CONFIGURED }}
|
||||
flavor: |
|
||||
latest=auto
|
||||
suffix=-${{ matrix.target_runtime }}-${{ matrix.php_version }}
|
||||
tags: |
|
||||
type=raw,value=dev,enable=${{ github.ref == format('refs/heads/{0}', 'dev') }}
|
||||
type=raw,value=staging,enable=${{ github.ref == format('refs/heads/{0}', 'staging') }}
|
||||
type=pep440,pattern={{raw}}
|
||||
type=pep440,pattern=v{{major}}.{{minor}}
|
||||
type=ref,event=branch,prefix=branch-
|
||||
type=ref,event=pr,prefix=pr-
|
||||
type=ref,event=tag
|
||||
env:
|
||||
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
target: ${{ matrix.target_runtime }}-runtime
|
||||
platforms: linux/amd64,linux/arm64
|
||||
builder: ${{ steps.buildx.outputs.name }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
annotations: ${{ steps.meta.outputs.annotations }}
|
||||
push: true
|
||||
sbom: true
|
||||
provenance: true
|
||||
build-args: |
|
||||
PHP_VERSION=${{ matrix.php_version }}
|
||||
PHP_BASE_TYPE=${{ matrix.php_base }}
|
||||
cache-from: |
|
||||
type=gha,scope=${{ matrix.target_runtime }}-${{ matrix.php_base }}-${{ matrix.php_version }}
|
||||
cache-to: |
|
||||
type=gha,mode=max,scope=${{ matrix.target_runtime }}-${{ matrix.php_base }}-${{ matrix.php_version }}
|
||||
${{ steps.cache.outputs.tags }}
|
||||
|
||||
# goss validate the image
|
||||
#
|
||||
# See: https://github.com/goss-org/goss
|
||||
- uses: e1himself/goss-installation-action@v1
|
||||
with:
|
||||
version: "v0.4.4"
|
||||
- name: Execute Goss tests
|
||||
run: |
|
||||
dgoss run \
|
||||
-v "./.env.testing:/var/www/.env" \
|
||||
-e "EXPECTED_PHP_VERSION=${{ matrix.php_version }}" \
|
||||
-e "PHP_BASE_TYPE=${{ matrix.php_base }}" \
|
||||
${{ steps.meta.outputs.tags }}
|
|
@ -1,22 +1,31 @@
|
|||
.DS_Store
|
||||
/.bash_history
|
||||
/.bash_profile
|
||||
/.bashrc
|
||||
/.composer
|
||||
/.env
|
||||
/.env.dottie-backup
|
||||
#/.git
|
||||
/.git-credentials
|
||||
/.gitconfig
|
||||
#/.gitignore
|
||||
/.idea
|
||||
/.vagrant
|
||||
/bootstrap/cache
|
||||
/docker-compose-state/
|
||||
/Homestead.json
|
||||
/Homestead.yaml
|
||||
/node_modules
|
||||
/npm-debug.log
|
||||
/public/hot
|
||||
/public/storage
|
||||
/public/vendor/horizon
|
||||
/storage/*.key
|
||||
/storage/docker
|
||||
/vendor
|
||||
/.idea
|
||||
/.vscode
|
||||
/.vagrant
|
||||
/docker-volumes
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
.env
|
||||
.DS_Store
|
||||
.bash_profile
|
||||
.bash_history
|
||||
.bashrc
|
||||
.gitconfig
|
||||
.git-credentials
|
||||
/.composer/
|
||||
/nginx.conf
|
||||
/yarn-error.log
|
||||
/public/build
|
||||
|
||||
# Exceptions - these *MUST* be last
|
||||
!/bootstrap/cache/.gitignore
|
||||
!/public/vendor/horizon/.gitignore
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
ignored:
|
||||
- DL3002 # warning: Last USER should not be root
|
||||
- DL3008 # warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
|
||||
- SC2046 # warning: Quote this to prevent word splitting.
|
||||
- SC2086 # info: Double quote to prevent globbing and word splitting.
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"MD013": false,
|
||||
"MD014": false
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
# See: https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md#rc-files
|
||||
|
||||
source-path=SCRIPTDIR
|
||||
|
||||
# Allow opening any 'source'd file, even if not specified as input
|
||||
external-sources=true
|
||||
|
||||
# Turn on warnings for unquoted variables with safe values
|
||||
enable=quote-safe-variables
|
||||
|
||||
# Turn on warnings for unassigned uppercase variables
|
||||
enable=check-unassigned-uppercase
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"recommendations": [
|
||||
"foxundermoon.shell-format",
|
||||
"timonwong.shellcheck",
|
||||
"jetmartin.bats",
|
||||
"aaron-bond.better-comments",
|
||||
"streetsidesoftware.code-spell-checker",
|
||||
"editorconfig.editorconfig",
|
||||
"github.vscode-github-actions",
|
||||
"bmewburn.vscode-intelephense-client",
|
||||
"redhat.vscode-yaml",
|
||||
"ms-azuretools.vscode-docker"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"shellformat.useEditorConfig": true,
|
||||
"[shellscript]": {
|
||||
"files.eol": "\n",
|
||||
"editor.defaultFormatter": "foxundermoon.shell-format"
|
||||
},
|
||||
"[yaml]": {
|
||||
"editor.defaultFormatter": "redhat.vscode-yaml"
|
||||
},
|
||||
"[dockercompose]": {
|
||||
"editor.defaultFormatter": "redhat.vscode-yaml",
|
||||
"editor.autoIndent": "advanced",
|
||||
},
|
||||
"yaml.schemas": {
|
||||
"https://json.schemastore.org/composer": "https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"
|
||||
},
|
||||
"files.associations": {
|
||||
".env": "shellscript",
|
||||
".env.*": "shellscript"
|
||||
}
|
||||
}
|
138
CHANGELOG.md
138
CHANGELOG.md
|
@ -1,6 +1,140 @@
|
|||
# Release Notes
|
||||
|
||||
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.11...dev)
|
||||
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.12.1...dev)
|
||||
|
||||
### Updates
|
||||
- Update DirectMessageController, add 72 hour delay for new accounts before they can send a DM ([61d105fd](https://github.com/pixelfed/pixelfed/commit/61d105fd))
|
||||
- Update AdminCuratedRegisterController, increase message length from 1000 to 3000 ([9a5e3471](https://github.com/pixelfed/pixelfed/commit/))
|
||||
- ([](https://github.com/pixelfed/pixelfed/commit/9a5e3471))
|
||||
|
||||
## [v0.12.1 (2024-05-07)](https://github.com/pixelfed/pixelfed/compare/v0.12.0...v0.12.1)
|
||||
|
||||
### Updates
|
||||
- Update ApiV1Dot1Controller, fix in app registration bug that prevents proper auth flow due to missing oauth scopes ([cbf996c9](https://github.com/pixelfed/pixelfed/commit/cbf996c9))
|
||||
- Update ConfigCacheService, fix database race condition and fallback to file config and enable by default ([60a62b59](https://github.com/pixelfed/pixelfed/commit/60a62b59))
|
||||
|
||||
## [v0.12.0 (2024-04-29)](https://github.com/pixelfed/pixelfed/compare/v0.11.13...v0.12.0)
|
||||
|
||||
### Updates
|
||||
|
||||
- Update SoftwareUpdateService, add command to refresh latest versions ([632f2cb6](https://github.com/pixelfed/pixelfed/commit/632f2cb6))
|
||||
- Update Post.vue, fix cache bug ([3a27e637](https://github.com/pixelfed/pixelfed/commit/3a27e637))
|
||||
- Update StatusHashtagService, use more efficient cached count ([592c8412](https://github.com/pixelfed/pixelfed/commit/592c8412))
|
||||
- Update DiscoverController, handle discover hashtag redirects ([18382e8a](https://github.com/pixelfed/pixelfed/commit/18382e8a))
|
||||
- Update ApiV1Controller, use admin filter service ([94503a1c](https://github.com/pixelfed/pixelfed/commit/94503a1c))
|
||||
- Update SearchApiV2Service, use more efficient query ([cee618e8](https://github.com/pixelfed/pixelfed/commit/cee618e8))
|
||||
- Update Curated Onboarding view, fix concierge form ([15ad69f7](https://github.com/pixelfed/pixelfed/commit/15ad69f7))
|
||||
- Update AP Profile Transformer, add `suspended` attribute ([25f3fa06](https://github.com/pixelfed/pixelfed/commit/25f3fa06))
|
||||
- Update AP Profile Transformer, fix movedTo attribute ([63100fe9](https://github.com/pixelfed/pixelfed/commit/63100fe9))
|
||||
- Update AP Profile Transformer, fix suspended attributes ([2e5e68e4](https://github.com/pixelfed/pixelfed/commit/2e5e68e4))
|
||||
- Update PrivacySettings controller, add cache invalidation ([e742d595](https://github.com/pixelfed/pixelfed/commit/e742d595))
|
||||
- Update ProfileController, preserve deleted actor objects for federated account deletion and use more efficient account cache lookup ([853a729f](https://github.com/pixelfed/pixelfed/commit/853a729f))
|
||||
- Update SiteController, add curatedOnboarding method that gracefully falls back to open registration when applicable ([95199843](https://github.com/pixelfed/pixelfed/commit/95199843))
|
||||
- Update AP transformers, add DeleteActor activity ([bcce1df6](https://github.com/pixelfed/pixelfed/commit/bcce1df6))
|
||||
- Update commands, add user account delete cli command to federate account deletion ([4aa0e25f](https://github.com/pixelfed/pixelfed/commit/4aa0e25f))
|
||||
- Update web-api popular accounts route to its own method to remove the breaking oauth scope bug ([a4bc5ce3](https://github.com/pixelfed/pixelfed/commit/a4bc5ce3))
|
||||
- Update config cache ([5e4d4eff](https://github.com/pixelfed/pixelfed/commit/5e4d4eff))
|
||||
- Update Config, use config_cache ([7785a2da](https://github.com/pixelfed/pixelfed/commit/7785a2da))
|
||||
- Update ApiV1Dot1Controller, use config_cache for in-app registration ([b0cb4456](https://github.com/pixelfed/pixelfed/commit/b0cb4456))
|
||||
- Update captcha, use config_cache helper ([8a89e3c9](https://github.com/pixelfed/pixelfed/commit/8a89e3c9))
|
||||
- Update custom emoji, add config_cache support ([481314cd](https://github.com/pixelfed/pixelfed/commit/481314cd))
|
||||
- Update ProfileController, fix permalink redirect bug ([75081e60](https://github.com/pixelfed/pixelfed/commit/75081e60))
|
||||
- Update admin css, use font-display:swap for nucleo icons ([8a0c456e](https://github.com/pixelfed/pixelfed/commit/8a0c456e))
|
||||
- Update PixelfedDirectoryController, fix boolean cast bug ([f08aab22](https://github.com/pixelfed/pixelfed/commit/f08aab22))
|
||||
- Update PixelfedDirectoryController, use cached stats ([f2f2a809](https://github.com/pixelfed/pixelfed/commit/f2f2a809))
|
||||
- Update AdminDirectoryController, fix type casting ([ad506e90](https://github.com/pixelfed/pixelfed/commit/ad506e90))
|
||||
- Update image pipeline, use config_cache ([a72188a7](https://github.com/pixelfed/pixelfed/commit/a72188a7))
|
||||
- Update cloud storage, use config_cache ([665581d8](https://github.com/pixelfed/pixelfed/commit/665581d8))
|
||||
- Update pixelfed.max_album_length, use config_cache ([fecbe189](https://github.com/pixelfed/pixelfed/commit/fecbe189))
|
||||
- Update media_types, use config_cache ([d670de17](https://github.com/pixelfed/pixelfed/commit/d670de17))
|
||||
- Update landing settings, use config_cache ([40478f25](https://github.com/pixelfed/pixelfed/commit/40478f25))
|
||||
- Update activitypub setting, use config_cache ([5071aaf4](https://github.com/pixelfed/pixelfed/commit/5071aaf4))
|
||||
- Update oauth setting, use config_cache ([ce228f7f](https://github.com/pixelfed/pixelfed/commit/ce228f7f))
|
||||
- Update stories config, use config_cache ([d1adb109](https://github.com/pixelfed/pixelfed/commit/d1adb109))
|
||||
- Update ig import, use config_cache ([da0e0ffa](https://github.com/pixelfed/pixelfed/commit/da0e0ffa))
|
||||
- Update autospam config, use config_cache ([a76cb5f4](https://github.com/pixelfed/pixelfed/commit/a76cb5f4))
|
||||
- Update app.name config, use config_cache ([911446c0](https://github.com/pixelfed/pixelfed/commit/911446c0))
|
||||
- Update UserObserver, fix type casting ([949e9979](https://github.com/pixelfed/pixelfed/commit/949e9979))
|
||||
- Update user_filters, use config_cache ([6ce513f8](https://github.com/pixelfed/pixelfed/commit/6ce513f8))
|
||||
- Update filesystems config, add to config_cache ([087b2791](https://github.com/pixelfed/pixelfed/commit/087b2791))
|
||||
- Update web-admin routes, add setting api routes ([828a456f](https://github.com/pixelfed/pixelfed/commit/828a456f))
|
||||
- Update hashtag component ([cee979ed](https://github.com/pixelfed/pixelfed/commit/cee979ed))
|
||||
- Update AdminReadMore component, add .prevent to click action ([704e7b12](https://github.com/pixelfed/pixelfed/commit/704e7b12))
|
||||
- Update admin dashboard, add admin settings partials ([eb487123](https://github.com/pixelfed/pixelfed/commit/eb487123))
|
||||
- Update admin settings, refactor to vue component ([674e560f](https://github.com/pixelfed/pixelfed/commit/674e560f))
|
||||
- Update ConfigCacheService, encrypt keys at rest ([3628b462](https://github.com/pixelfed/pixelfed/commit/3628b462))
|
||||
- Update RemoteFollowImportRecent, use MediaPathService ([5162c070](https://github.com/pixelfed/pixelfed/commit/5162c070))
|
||||
- Update AdminSettingsController, add user filter max limit settings ([ac1f0748](https://github.com/pixelfed/pixelfed/commit/ac1f0748))
|
||||
- Update AdminSettingsController, add AdminSettingsService ([dcc5f416](https://github.com/pixelfed/pixelfed/commit/dcc5f416))
|
||||
- Update AdminSettings component, fix user settings ([aba1e13d](https://github.com/pixelfed/pixelfed/commit/aba1e13d))
|
||||
- Update AdminInstances component ([ec2fdd61](https://github.com/pixelfed/pixelfed/commit/ec2fdd61))
|
||||
- Update AdminSettings, add max_account_size support ([2dcbc1d5](https://github.com/pixelfed/pixelfed/commit/2dcbc1d5))
|
||||
- Update AdminSettings, use better validation for user integer settings ([d946afcc](https://github.com/pixelfed/pixelfed/commit/d946afcc))
|
||||
- Update spa sass, fix timestamp dark mode bug ([4147f7c5](https://github.com/pixelfed/pixelfed/commit/4147f7c5))
|
||||
- Update relationships view, fix unfollow hashtag bug. Fixes #5008 ([8c693640](https://github.com/pixelfed/pixelfed/commit/8c693640))
|
||||
- Update PrivacySettings controller, refresh RelationshipService when unmute/unblocking ([b7322b68](https://github.com/pixelfed/pixelfed/commit/b7322b68))
|
||||
- Update ApiV1Controller, improve refresh relations logic when (un)muting or (un)blocking ([b8e96a5f](https://github.com/pixelfed/pixelfed/commit/b8e96a5f))
|
||||
- Update context menu, add mute/block/unfollow actions and update relationship store accordingly ([81d1e0fd](https://github.com/pixelfed/pixelfed/commit/81d1e0fd))
|
||||
- Update docker env, fix config_cache. Fixes #5033 ([858fcbf6](https://github.com/pixelfed/pixelfed/commit/858fcbf6))
|
||||
- Update UnfollowPipeline, fix follower count cache bug ([6bdf73de](https://github.com/pixelfed/pixelfed/commit/6bdf73de))
|
||||
- Update VideoPresenter component, add webkit-playsinline attribute to video element to prevent the full screen video player ([ad032916](https://github.com/pixelfed/pixelfed/commit/ad032916))
|
||||
- Update VideoPlayer component, add playsinline attribute to video element ([8af23607](https://github.com/pixelfed/pixelfed/commit/8af23607))
|
||||
- Update StatusController, refactor status embeds ([9a7acc12](https://github.com/pixelfed/pixelfed/commit/9a7acc12))
|
||||
- Update ProfileController, refactor profile embeds ([8b8b1ffc](https://github.com/pixelfed/pixelfed/commit/8b8b1ffc))
|
||||
- Update profile embed view, fix height bug ([65166570](https://github.com/pixelfed/pixelfed/commit/65166570))
|
||||
- Update CustomEmojiService, only return local emoji ([7f8bba44](https://github.com/pixelfed/pixelfed/commit/7f8bba44))
|
||||
- Update Like model, increase max likes per day from 500 to 1500 ([4223119f](https://github.com/pixelfed/pixelfed/commit/4223119f))
|
||||
|
||||
## [v0.11.13 (2024-03-05)](https://github.com/pixelfed/pixelfed/compare/v0.11.12...v0.11.13)
|
||||
|
||||
### Features
|
||||
|
||||
- Account Migrations ([#4968](https://github.com/pixelfed/pixelfed/pull/4968)) ([4a6be6212](https://github.com/pixelfed/pixelfed/pull/4968/commits/4a6be6212))
|
||||
- Curated Onboarding ([#4946](https://github.com/pixelfed/pixelfed/pull/4946)) ([8dac2caf](https://github.com/pixelfed/pixelfed/commit/8dac2caf))
|
||||
- Add Curated Onboarding Templates ([071163b4](https://github.com/pixelfed/pixelfed/commit/071163b4))
|
||||
- Add Remote Reports to Admin Dashboard Reports page ([ef0ff78e](https://github.com/pixelfed/pixelfed/commit/ef0ff78e))
|
||||
- Improved Docker Support ([#4844](https://github.com/pixelfed/pixelfed/pull/4844)) ([d92cf7f](https://github.com/pixelfed/pixelfed/commit/d92cf7f))
|
||||
|
||||
### Updates
|
||||
|
||||
- Update Inbox, cast live filters to lowercase ([d835e0ad](https://github.com/pixelfed/pixelfed/commit/d835e0ad))
|
||||
- Update federation config, increase default timeline days falloff to 90 days from 2 days. Fixes #4905 ([011834f4](https://github.com/pixelfed/pixelfed/commit/011834f4))
|
||||
- Update cache config, use predis as default redis driver client ([ea6b1623](https://github.com/pixelfed/pixelfed/commit/ea6b1623))
|
||||
- Update .gitattributes to collapse diffs on generated files ([ThisIsMissEm](https://github.com/pixelfed/pixelfed/commit/9978b2b9))
|
||||
- Update api v1/v2 instance endpoints, bump mastoapi version from 2.7.2 to 3.5.3 ([545f7d5e](https://github.com/pixelfed/pixelfed/commit/545f7d5e))
|
||||
- Update ApiV1Controller, implement better limit logic to gracefully handle requests with limits that exceed the max ([1f74a95d](https://github.com/pixelfed/pixelfed/commit/1f74a95d))
|
||||
- Update AdminCuratedRegisterController, show oldest applications first ([c4dde641](https://github.com/pixelfed/pixelfed/commit/c4dde641))
|
||||
- Update Directory logic, add curated onboarding support ([59c70239](https://github.com/pixelfed/pixelfed/commit/59c70239))
|
||||
- Update Inbox and StatusObserver, fix silently rejected direct messages due to saveQuietly which failed to generate a snowflake id ([089ba3c4](https://github.com/pixelfed/pixelfed/commit/089ba3c4))
|
||||
- Update Curated Onboarding dashboard, improve application filtering and make it easier to distinguish response state ([2b5d7235](https://github.com/pixelfed/pixelfed/commit/2b5d7235))
|
||||
- Update AdminReports, add story reports and fix cs ([767522a8](https://github.com/pixelfed/pixelfed/commit/767522a8))
|
||||
- Update AdminReportController, add story report support ([a16309ac](https://github.com/pixelfed/pixelfed/commit/a16309ac))
|
||||
- Update kb, add email confirmation issues page ([2f48df8c](https://github.com/pixelfed/pixelfed/commit/2f48df8c))
|
||||
- Update AdminCuratedRegisterController, filter confirmation activities from activitylog ([ab9ecb6e](https://github.com/pixelfed/pixelfed/commit/ab9ecb6e))
|
||||
- Update Inbox, fix flag validation condition, allow profile reports ([402a4607](https://github.com/pixelfed/pixelfed/commit/402a4607))
|
||||
- Update AccountTransformer, fix follower/following count visibility bug ([542d1106](https://github.com/pixelfed/pixelfed/commit/542d1106))
|
||||
- Update ProfileMigration model, add target relation ([3f053997](https://github.com/pixelfed/pixelfed/commit/3f053997))
|
||||
- Update ApiV1Controller, update Notifications endpoint to filter notifications with missing activities ([a933615b](https://github.com/pixelfed/pixelfed/commit/a933615b))
|
||||
- Update ApiV1Controller, fix public timeline scope, properly support both local + remote parameters ([d6eac655](https://github.com/pixelfed/pixelfed/commit/d6eac655))
|
||||
- Update ApiV1Controller, handle public feed parameter bug to gracefully fallback to min_id=1 when max_id=0 ([e3826c58](https://github.com/pixelfed/pixelfed/commit/e3826c58))
|
||||
- Update ApiV1Controller, fix hashtag feed to include private posts from accounts you follow or your own, and your own unlisted posts ([3b5500b3](https://github.com/pixelfed/pixelfed/commit/3b5500b3))
|
||||
- Update checkpoint view, improve input autocomplete. Fixes ([#4959](https://github.com/pixelfed/pixelfed/pull/4959)) ([d18824e7](https://github.com/pixelfed/pixelfed/commit/d18824e7))
|
||||
- Update navbar.vue, removes the 50px limit ([#4969](https://github.com/pixelfed/pixelfed/pull/4969)) ([7fd5599](https://github.com/pixelfed/pixelfed/commit/7fd5599))
|
||||
- Update ComposeModal.vue, add an informative UI error message when trying to create a mixed media album ([#4886](https://github.com/pixelfed/pixelfed/pull/4886)) ([fd4f41a](https://github.com/pixelfed/pixelfed/commit/fd4f41a))
|
||||
|
||||
## [v0.11.12 (2024-02-16)](https://github.com/pixelfed/pixelfed/compare/v0.11.11...v0.11.12)
|
||||
|
||||
### Features
|
||||
- Autospam Live Filters - block remote activities based on comma separated keywords ([40b45b2a](https://github.com/pixelfed/pixelfed/commit/40b45b2a))
|
||||
- Added Software Update banner to admin home feeds ([b0fb1988](https://github.com/pixelfed/pixelfed/commit/b0fb1988))
|
||||
|
||||
### Updates
|
||||
|
||||
- Update ApiV1Controller, fix network timeline ([0faf59e3](https://github.com/pixelfed/pixelfed/commit/0faf59e3))
|
||||
- Update public/network timelines, fix non-redis response and fix reblogs in home feed ([8b4ac5cc](https://github.com/pixelfed/pixelfed/commit/8b4ac5cc))
|
||||
- Update Federation, use proper Content-Type headers for following/follower collections ([fb0bb9a3](https://github.com/pixelfed/pixelfed/commit/fb0bb9a3))
|
||||
- Update ActivityPubFetchService, enforce stricter Content-Type validation ([1232cfc8](https://github.com/pixelfed/pixelfed/commit/1232cfc8))
|
||||
- Update status view, fix unlisted/private scope bug ([0f3ca194](https://github.com/pixelfed/pixelfed/commit/0f3ca194))
|
||||
|
||||
## [v0.11.11 (2024-02-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.10...v0.11.11)
|
||||
|
||||
|
@ -27,7 +161,6 @@
|
|||
### Federation
|
||||
- Update Privacy Settings, add support for Mastodon `indexable` search flag ([fc24630e](https://github.com/pixelfed/pixelfed/commit/fc24630e))
|
||||
- Update AP Helpers, consume actor `indexable` attribute ([fbdcdd9d](https://github.com/pixelfed/pixelfed/commit/fbdcdd9d))
|
||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||
|
||||
### Updates
|
||||
- Update FollowerService, add forget method to RelationshipService call to reduce load when mass purging ([347e4f59](https://github.com/pixelfed/pixelfed/commit/347e4f59))
|
||||
|
@ -112,7 +245,6 @@
|
|||
- Update PublicApiController, consume InstanceService blocked domains for account and statuses endpoints ([01b33fb3](https://github.com/pixelfed/pixelfed/commit/01b33fb3))
|
||||
- Update ApiV1Controller, enforce blocked instance domain logic ([5b284cac](https://github.com/pixelfed/pixelfed/commit/5b284cac))
|
||||
- Update ApiV2Controller, add vapid key to instance object. Thanks thisismissem! ([4d02d6f1](https://github.com/pixelfed/pixelfed/commit/4d02d6f1))
|
||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||
|
||||
## [v0.11.9 (2023-08-21)](https://github.com/pixelfed/pixelfed/compare/v0.11.8...v0.11.9)
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# See: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
|
||||
|
||||
# These owners will be the default owners for everything in
|
||||
# the repo. Unless a later match takes precedence,
|
||||
* @dansup
|
||||
|
||||
# Docker related files
|
||||
.editorconfig @jippi @dansup
|
||||
.env @jippi @dansup
|
||||
.env.* @jippi @dansup
|
||||
.hadolint.yaml @jippi @dansup
|
||||
.shellcheckrc @jippi @dansup
|
||||
/.github/ @jippi @dansup
|
||||
/docker/ @jippi @dansup
|
||||
/tests/ @jippi @dansup
|
||||
docker-compose.migrate.yml @jippi @dansup
|
||||
docker-compose.yml @jippi @dansup
|
||||
goss.yaml @jippi @dansup
|
|
@ -0,0 +1,307 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
# See https://hub.docker.com/r/docker/dockerfile
|
||||
|
||||
#######################################################
|
||||
# Configuration
|
||||
#######################################################
|
||||
|
||||
# See: https://github.com/mlocati/docker-php-extension-installer
|
||||
ARG DOCKER_PHP_EXTENSION_INSTALLER_VERSION="2.1.80"
|
||||
|
||||
# See: https://github.com/composer/composer
|
||||
ARG COMPOSER_VERSION="2.6"
|
||||
|
||||
# See: https://nginx.org/
|
||||
ARG NGINX_VERSION="1.25.3"
|
||||
|
||||
# See: https://github.com/ddollar/forego
|
||||
ARG FOREGO_VERSION="0.17.2"
|
||||
|
||||
# See: https://github.com/hairyhenderson/gomplate
|
||||
ARG GOMPLATE_VERSION="v3.11.6"
|
||||
|
||||
# See: https://github.com/jippi/dottie
|
||||
ARG DOTTIE_VERSION="v0.9.5"
|
||||
|
||||
###
|
||||
# PHP base configuration
|
||||
###
|
||||
|
||||
# See: https://hub.docker.com/_/php/tags
|
||||
ARG PHP_VERSION="8.1"
|
||||
|
||||
# See: https://github.com/docker-library/docs/blob/master/php/README.md#image-variants
|
||||
ARG PHP_BASE_TYPE="apache"
|
||||
ARG PHP_DEBIAN_RELEASE="bullseye"
|
||||
|
||||
ARG RUNTIME_UID=33 # often called 'www-data'
|
||||
ARG RUNTIME_GID=33 # often called 'www-data'
|
||||
|
||||
# APT extra packages
|
||||
ARG APT_PACKAGES_EXTRA=
|
||||
|
||||
# Extensions installed via [pecl install]
|
||||
# ! NOTE: imagick is installed from [master] branch on GitHub due to 8.3 bug on ARM that haven't
|
||||
# ! been released yet (after +10 months)!
|
||||
# ! See: https://github.com/Imagick/imagick/pull/641
|
||||
ARG PHP_PECL_EXTENSIONS="redis https://codeload.github.com/Imagick/imagick/tar.gz/28f27044e435a2b203e32675e942eb8de620ee58"
|
||||
ARG PHP_PECL_EXTENSIONS_EXTRA=
|
||||
|
||||
# Extensions installed via [docker-php-ext-install]
|
||||
ARG PHP_EXTENSIONS="intl bcmath zip pcntl exif curl gd"
|
||||
ARG PHP_EXTENSIONS_EXTRA=""
|
||||
ARG PHP_EXTENSIONS_DATABASE="pdo_pgsql pdo_mysql pdo_sqlite"
|
||||
|
||||
# GPG key for nginx apt repository
|
||||
ARG NGINX_GPGKEY="573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62"
|
||||
|
||||
# GPP key path for nginx apt repository
|
||||
ARG NGINX_GPGKEY_PATH="/usr/share/keyrings/nginx-archive-keyring.gpg"
|
||||
|
||||
#######################################################
|
||||
# Docker "copy from" images
|
||||
#######################################################
|
||||
|
||||
# Composer docker image from Docker Hub
|
||||
#
|
||||
# NOTE: Docker will *not* pull this image unless it's referenced (via build target)
|
||||
FROM composer:${COMPOSER_VERSION} AS composer-image
|
||||
|
||||
# php-extension-installer image from Docker Hub
|
||||
#
|
||||
# NOTE: Docker will *not* pull this image unless it's referenced (via build target)
|
||||
FROM mlocati/php-extension-installer:${DOCKER_PHP_EXTENSION_INSTALLER_VERSION} AS php-extension-installer
|
||||
|
||||
# nginx webserver from Docker Hub.
|
||||
# Used to copy some docker-entrypoint files for [nginx-runtime]
|
||||
#
|
||||
# NOTE: Docker will *not* pull this image unless it's referenced (via build target)
|
||||
FROM nginx:${NGINX_VERSION} AS nginx-image
|
||||
|
||||
# Forego is a Procfile "runner" that makes it trival to run multiple
|
||||
# processes under a simple init / PID 1 process.
|
||||
#
|
||||
# NOTE: Docker will *not* pull this image unless it's referenced (via build target)
|
||||
#
|
||||
# See: https://github.com/nginx-proxy/forego
|
||||
FROM nginxproxy/forego:${FOREGO_VERSION}-debian AS forego-image
|
||||
|
||||
# Dottie makes working with .env files easier and safer
|
||||
#
|
||||
# NOTE: Docker will *not* pull this image unless it's referenced (via build target)
|
||||
#
|
||||
# See: https://github.com/jippi/dottie
|
||||
FROM ghcr.io/jippi/dottie:${DOTTIE_VERSION} AS dottie-image
|
||||
|
||||
# gomplate-image grabs the gomplate binary from GitHub releases
|
||||
#
|
||||
# It's in its own layer so it can be fetched in parallel with other build steps
|
||||
FROM php:${PHP_VERSION}-${PHP_BASE_TYPE}-${PHP_DEBIAN_RELEASE} AS gomplate-image
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG TARGETOS
|
||||
ARG GOMPLATE_VERSION
|
||||
|
||||
RUN set -ex \
|
||||
&& curl \
|
||||
--silent \
|
||||
--show-error \
|
||||
--location \
|
||||
--output /usr/local/bin/gomplate \
|
||||
https://github.com/hairyhenderson/gomplate/releases/download/${GOMPLATE_VERSION}/gomplate_${TARGETOS}-${TARGETARCH} \
|
||||
&& chmod +x /usr/local/bin/gomplate \
|
||||
&& /usr/local/bin/gomplate --version
|
||||
|
||||
#######################################################
|
||||
# Base image
|
||||
#######################################################
|
||||
|
||||
FROM php:${PHP_VERSION}-${PHP_BASE_TYPE}-${PHP_DEBIAN_RELEASE} AS base
|
||||
|
||||
ARG BUILDKIT_SBOM_SCAN_STAGE="true"
|
||||
|
||||
ARG APT_PACKAGES_EXTRA
|
||||
ARG PHP_DEBIAN_RELEASE
|
||||
ARG PHP_VERSION
|
||||
ARG RUNTIME_GID
|
||||
ARG RUNTIME_UID
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
ENV DEBIAN_FRONTEND="noninteractive"
|
||||
|
||||
# Ensure we run all scripts through 'bash' rather than 'sh'
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
RUN set -ex \
|
||||
&& mkdir -pv /var/www/ \
|
||||
&& chown -R ${RUNTIME_UID}:${RUNTIME_GID} /var/www
|
||||
|
||||
WORKDIR /var/www/
|
||||
|
||||
ENV APT_PACKAGES_EXTRA=${APT_PACKAGES_EXTRA}
|
||||
|
||||
# Install and configure base layer
|
||||
COPY docker/shared/root/docker/install/base.sh /docker/install/base.sh
|
||||
|
||||
RUN --mount=type=cache,id=pixelfed-apt-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/lib/apt \
|
||||
--mount=type=cache,id=pixelfed-apt-cache-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/cache/apt \
|
||||
/docker/install/base.sh
|
||||
|
||||
#######################################################
|
||||
# PHP: extensions
|
||||
#######################################################
|
||||
|
||||
FROM base AS php-extensions
|
||||
|
||||
ARG PHP_DEBIAN_RELEASE
|
||||
ARG PHP_EXTENSIONS
|
||||
ARG PHP_EXTENSIONS_DATABASE
|
||||
ARG PHP_EXTENSIONS_EXTRA
|
||||
ARG PHP_PECL_EXTENSIONS
|
||||
ARG PHP_PECL_EXTENSIONS_EXTRA
|
||||
ARG PHP_VERSION
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
COPY --from=php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
|
||||
|
||||
COPY docker/shared/root/docker/install/php-extensions.sh /docker/install/php-extensions.sh
|
||||
|
||||
RUN --mount=type=cache,id=pixelfed-pear-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/tmp/pear \
|
||||
--mount=type=cache,id=pixelfed-apt-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/lib/apt \
|
||||
--mount=type=cache,id=pixelfed-apt-cache-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/cache/apt \
|
||||
PHP_EXTENSIONS=${PHP_EXTENSIONS} \
|
||||
PHP_EXTENSIONS_DATABASE=${PHP_EXTENSIONS_DATABASE} \
|
||||
PHP_EXTENSIONS_EXTRA=${PHP_EXTENSIONS_EXTRA} \
|
||||
PHP_PECL_EXTENSIONS=${PHP_PECL_EXTENSIONS} \
|
||||
PHP_PECL_EXTENSIONS_EXTRA=${PHP_PECL_EXTENSIONS_EXTRA} \
|
||||
/docker/install/php-extensions.sh
|
||||
|
||||
#######################################################
|
||||
# PHP: composer and source code
|
||||
#######################################################
|
||||
|
||||
FROM php-extensions AS composer-and-src
|
||||
|
||||
ARG PHP_VERSION
|
||||
ARG PHP_DEBIAN_RELEASE
|
||||
ARG RUNTIME_UID
|
||||
ARG RUNTIME_GID
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
# Make sure composer cache is targeting our cache mount later
|
||||
ENV COMPOSER_CACHE_DIR="/cache/composer"
|
||||
|
||||
# Don't enforce any memory limits for composer
|
||||
ENV COMPOSER_MEMORY_LIMIT=-1
|
||||
|
||||
# Disable interactvitity from composer
|
||||
ENV COMPOSER_NO_INTERACTION=1
|
||||
|
||||
# Copy composer from https://hub.docker.com/_/composer
|
||||
COPY --link --from=composer-image /usr/bin/composer /usr/bin/composer
|
||||
|
||||
#! Changing user to runtime user
|
||||
USER ${RUNTIME_UID}:${RUNTIME_GID}
|
||||
|
||||
# Install composer dependencies
|
||||
# NOTE: we skip the autoloader generation here since we don't have all files avaliable (yet)
|
||||
RUN --mount=type=cache,id=pixelfed-composer-${PHP_VERSION},sharing=locked,target=/cache/composer \
|
||||
--mount=type=bind,source=composer.json,target=/var/www/composer.json \
|
||||
--mount=type=bind,source=composer.lock,target=/var/www/composer.lock \
|
||||
set -ex \
|
||||
&& composer install --prefer-dist --no-autoloader --ignore-platform-reqs
|
||||
|
||||
# Copy all other files over
|
||||
COPY --chown=${RUNTIME_UID}:${RUNTIME_GID} . /var/www/
|
||||
|
||||
#######################################################
|
||||
# Runtime: base
|
||||
#######################################################
|
||||
|
||||
FROM php-extensions AS shared-runtime
|
||||
|
||||
ARG RUNTIME_GID
|
||||
ARG RUNTIME_UID
|
||||
|
||||
ENV RUNTIME_UID=${RUNTIME_UID}
|
||||
ENV RUNTIME_GID=${RUNTIME_GID}
|
||||
|
||||
COPY --link --from=forego-image /usr/local/bin/forego /usr/local/bin/forego
|
||||
COPY --link --from=dottie-image /dottie /usr/local/bin/dottie
|
||||
COPY --link --from=gomplate-image /usr/local/bin/gomplate /usr/local/bin/gomplate
|
||||
COPY --link --from=composer-image /usr/bin/composer /usr/bin/composer
|
||||
COPY --link --from=composer-and-src --chown=${RUNTIME_UID}:${RUNTIME_GID} /var/www /var/www
|
||||
|
||||
#! Changing user to runtime user
|
||||
USER ${RUNTIME_UID}:${RUNTIME_GID}
|
||||
|
||||
# Generate optimized autoloader now that we have all files around
|
||||
RUN set -ex \
|
||||
&& ENABLE_CONFIG_CACHE=false composer dump-autoload --optimize
|
||||
|
||||
USER root
|
||||
|
||||
# for detail why storage is copied this way, pls refer to https://github.com/pixelfed/pixelfed/pull/2137#discussion_r434468862
|
||||
RUN set -ex \
|
||||
&& cp --recursive --link --preserve=all storage storage.skel \
|
||||
&& rm -rf html && ln -s public html
|
||||
|
||||
COPY docker/shared/root /
|
||||
|
||||
ENTRYPOINT ["/docker/entrypoint.sh"]
|
||||
|
||||
#######################################################
|
||||
# Runtime: apache
|
||||
#######################################################
|
||||
|
||||
FROM shared-runtime AS apache-runtime
|
||||
|
||||
COPY docker/apache/root /
|
||||
|
||||
RUN set -ex \
|
||||
&& a2enmod rewrite remoteip proxy proxy_http \
|
||||
&& a2enconf remoteip
|
||||
|
||||
CMD ["apache2-foreground"]
|
||||
|
||||
#######################################################
|
||||
# Runtime: fpm
|
||||
#######################################################
|
||||
|
||||
FROM shared-runtime AS fpm-runtime
|
||||
|
||||
COPY docker/fpm/root /
|
||||
|
||||
CMD ["php-fpm"]
|
||||
|
||||
#######################################################
|
||||
# Runtime: nginx
|
||||
#######################################################
|
||||
|
||||
FROM shared-runtime AS nginx-runtime
|
||||
|
||||
ARG NGINX_GPGKEY
|
||||
ARG NGINX_GPGKEY_PATH
|
||||
ARG NGINX_VERSION
|
||||
ARG PHP_DEBIAN_RELEASE
|
||||
ARG PHP_VERSION
|
||||
ARG TARGETPLATFORM
|
||||
|
||||
# Install nginx dependencies
|
||||
RUN --mount=type=cache,id=pixelfed-apt-lists-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/lib/apt/lists \
|
||||
--mount=type=cache,id=pixelfed-apt-cache-${PHP_VERSION}-${PHP_DEBIAN_RELEASE}-${TARGETPLATFORM},sharing=locked,target=/var/cache/apt \
|
||||
set -ex \
|
||||
&& gpg1 --keyserver "hkp://keyserver.ubuntu.com:80" --keyserver-options timeout=10 --recv-keys "${NGINX_GPGKEY}" \
|
||||
&& gpg1 --export "$NGINX_GPGKEY" > "$NGINX_GPGKEY_PATH" \
|
||||
&& echo "deb [signed-by=${NGINX_GPGKEY_PATH}] https://nginx.org/packages/mainline/debian/ ${PHP_DEBIAN_RELEASE} nginx" >> /etc/apt/sources.list.d/nginx.list \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends nginx=${NGINX_VERSION}*
|
||||
|
||||
# copy docker entrypoints from the *real* nginx image directly
|
||||
COPY --link --from=nginx-image /docker-entrypoint.d /docker/entrypoint.d/
|
||||
COPY docker/nginx/root /
|
||||
COPY docker/nginx/Procfile .
|
||||
|
||||
STOPSIGNAL SIGQUIT
|
||||
|
||||
CMD ["forego", "start", "-r"]
|
|
@ -82,7 +82,7 @@ class AvatarStorage extends Command
|
|||
|
||||
$this->line(' ');
|
||||
|
||||
if(config_cache('pixelfed.cloud_storage')) {
|
||||
if((bool) config_cache('pixelfed.cloud_storage')) {
|
||||
$this->info('✅ - Cloud storage configured');
|
||||
$this->line(' ');
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ class AvatarStorage extends Command
|
|||
$this->line(' ');
|
||||
}
|
||||
|
||||
if(config_cache('pixelfed.cloud_storage') && config('instance.avatar.local_to_cloud')) {
|
||||
if((bool) config_cache('pixelfed.cloud_storage') && config('instance.avatar.local_to_cloud')) {
|
||||
$disk = Storage::disk(config_cache('filesystems.cloud'));
|
||||
$exists = $disk->exists('cache/avatars/default.jpg');
|
||||
$state = $exists ? '✅' : '❌';
|
||||
|
@ -100,7 +100,7 @@ class AvatarStorage extends Command
|
|||
$this->info($msg);
|
||||
}
|
||||
|
||||
$options = config_cache('pixelfed.cloud_storage') && config('instance.avatar.local_to_cloud') ?
|
||||
$options = (bool) config_cache('pixelfed.cloud_storage') && config('instance.avatar.local_to_cloud') ?
|
||||
[
|
||||
'Cancel',
|
||||
'Upload default avatar to cloud',
|
||||
|
@ -164,7 +164,7 @@ class AvatarStorage extends Command
|
|||
|
||||
protected function uploadAvatarsToCloud()
|
||||
{
|
||||
if(!config_cache('pixelfed.cloud_storage') || !config('instance.avatar.local_to_cloud')) {
|
||||
if(!(bool) config_cache('pixelfed.cloud_storage') || !config('instance.avatar.local_to_cloud')) {
|
||||
$this->error('Enable cloud storage and avatar cloud storage to perform this action');
|
||||
return;
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ class AvatarStorage extends Command
|
|||
return;
|
||||
}
|
||||
|
||||
if(config_cache('pixelfed.cloud_storage') == false && config_cache('federation.avatars.store_local') == false) {
|
||||
if((bool) config_cache('pixelfed.cloud_storage') == false && config_cache('federation.avatars.store_local') == false) {
|
||||
$this->error('You have cloud storage disabled and local avatar storage disabled, we cannot refetch avatars.');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class AvatarStorageDeepClean extends Command
|
|||
$this->line(' ');
|
||||
|
||||
$storage = [
|
||||
'cloud' => boolval(config_cache('pixelfed.cloud_storage')),
|
||||
'cloud' => (bool) config_cache('pixelfed.cloud_storage'),
|
||||
'local' => boolval(config_cache('federation.avatars.store_local'))
|
||||
];
|
||||
|
||||
|
|
|
@ -35,12 +35,16 @@ class CloudMediaMigrate extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$enabled = config('pixelfed.cloud_storage');
|
||||
$enabled = (bool) config_cache('pixelfed.cloud_storage');
|
||||
if(!$enabled) {
|
||||
$this->error('Cloud storage not enabled. Exiting...');
|
||||
return;
|
||||
}
|
||||
|
||||
if(!$this->confirm('Are you sure you want to proceed?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$limit = $this->option('limit');
|
||||
$hugeMode = $this->option('huge');
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Media;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Services\MediaService;
|
||||
use App\Services\StatusService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class FetchMissingMediaMimeType extends Command
|
||||
{
|
||||
|
@ -29,20 +29,20 @@ class FetchMissingMediaMimeType extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
foreach(Media::whereNotNull(['remote_url', 'status_id'])->whereNull('mime')->lazyByIdDesc(50, 'id') as $media) {
|
||||
foreach (Media::whereNotNull(['remote_url', 'status_id'])->whereNull('mime')->lazyByIdDesc(50, 'id') as $media) {
|
||||
$res = Http::retry(2, 100, throw: false)->head($media->remote_url);
|
||||
|
||||
if(!$res->successful()) {
|
||||
if (! $res->successful()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!in_array($res->header('content-type'), explode(',',config('pixelfed.media_types')))) {
|
||||
if (! in_array($res->header('content-type'), explode(',', config_cache('pixelfed.media_types')))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$media->mime = $res->header('content-type');
|
||||
|
||||
if($res->hasHeader('content-length')) {
|
||||
if ($res->hasHeader('content-length')) {
|
||||
$media->size = $res->header('content-length');
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class FetchMissingMediaMimeType extends Command
|
|||
|
||||
MediaService::del($media->status_id);
|
||||
StatusService::del($media->status_id);
|
||||
$this->info('mid:'.$media->id . ' (' . $res->header('content-type') . ':' . $res->header('content-length') . ' bytes)');
|
||||
$this->info('mid:'.$media->id.' ('.$res->header('content-type').':'.$res->header('content-length').' bytes)');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class FixMediaDriver extends Command
|
|||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
if(config_cache('pixelfed.cloud_storage') == false) {
|
||||
if((bool) config_cache('pixelfed.cloud_storage') == false) {
|
||||
$this->error('Cloud storage not enabled, exiting...');
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class MediaCloudUrlRewrite extends Command implements PromptsForMissingInput
|
|||
|
||||
protected function preflightCheck()
|
||||
{
|
||||
if(config_cache('pixelfed.cloud_storage') != true) {
|
||||
if(!(bool) config_cache('pixelfed.cloud_storage')) {
|
||||
$this->info('Error: Cloud storage is not enabled!');
|
||||
$this->error('Aborting...');
|
||||
exit;
|
||||
|
|
|
@ -45,7 +45,7 @@ class MediaS3GarbageCollector extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$enabled = in_array(config_cache('pixelfed.cloud_storage'), ['1', true, 'true']);
|
||||
$enabled = (bool) config_cache('pixelfed.cloud_storage');
|
||||
if(!$enabled) {
|
||||
$this->error('Cloud storage not enabled. Exiting...');
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Services\Internal\SoftwareUpdateService;
|
||||
use Cache;
|
||||
|
||||
class SoftwareUpdateRefresh extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:software-update-refresh';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Refresh latest software version data';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$key = SoftwareUpdateService::cacheKey();
|
||||
Cache::forget($key);
|
||||
Cache::remember($key, 1209600, function() {
|
||||
return SoftwareUpdateService::fetchLatest();
|
||||
});
|
||||
$this->info('Succesfully updated software versions!');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Instance;
|
||||
use App\Profile;
|
||||
use App\Transformer\ActivityPub\Verb\DeleteActor;
|
||||
use App\User;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Pool;
|
||||
use Illuminate\Console\Command;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\search;
|
||||
use function Laravel\Prompts\table;
|
||||
|
||||
class UserAccountDelete extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:user-account-delete';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Federate Account Deletion';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$id = search(
|
||||
label: 'Search for the account to delete by username',
|
||||
placeholder: 'john.appleseed',
|
||||
options: fn (string $value) => strlen($value) > 0
|
||||
? User::withTrashed()->whereStatus('deleted')->where('username', 'like', "%{$value}%")->pluck('username', 'id')->all()
|
||||
: [],
|
||||
);
|
||||
|
||||
$user = User::withTrashed()->find($id);
|
||||
|
||||
table(
|
||||
['Username', 'Name', 'Email', 'Created'],
|
||||
[[$user->username, $user->name, $user->email, $user->created_at]]
|
||||
);
|
||||
|
||||
$confirmed = confirm(
|
||||
label: 'Do you want to federate this account deletion?',
|
||||
default: false,
|
||||
yes: 'Proceed',
|
||||
no: 'Cancel',
|
||||
hint: 'This action is irreversible'
|
||||
);
|
||||
|
||||
if (! $confirmed) {
|
||||
$this->error('Aborting...');
|
||||
exit;
|
||||
}
|
||||
|
||||
$profile = Profile::withTrashed()->find($user->profile_id);
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($profile, new DeleteActor());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
|
||||
$audience = Instance::whereNotNull(['shared_inbox', 'nodeinfo_last_fetched'])
|
||||
->where('nodeinfo_last_fetched', '>', now()->subHours(12))
|
||||
->distinct()
|
||||
->pluck('shared_inbox');
|
||||
|
||||
$payload = json_encode($activity);
|
||||
|
||||
$client = new Client([
|
||||
'timeout' => 10,
|
||||
]);
|
||||
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
|
||||
$requests = function ($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach ($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function () use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
],
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => 50,
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
},
|
||||
]);
|
||||
|
||||
$promise = $pool->promise();
|
||||
|
||||
$promise->wait();
|
||||
}
|
||||
}
|
|
@ -25,31 +25,32 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->command('media:optimize')->hourlyAt(40);
|
||||
$schedule->command('media:gc')->hourlyAt(5);
|
||||
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
||||
$schedule->command('story:gc')->everyFiveMinutes();
|
||||
$schedule->command('gc:failedjobs')->dailyAt(3);
|
||||
$schedule->command('gc:passwordreset')->dailyAt('09:41');
|
||||
$schedule->command('gc:sessions')->twiceDaily(13, 23);
|
||||
$schedule->command('media:optimize')->hourlyAt(40)->onOneServer();
|
||||
$schedule->command('media:gc')->hourlyAt(5)->onOneServer();
|
||||
$schedule->command('horizon:snapshot')->everyFiveMinutes()->onOneServer();
|
||||
$schedule->command('story:gc')->everyFiveMinutes()->onOneServer();
|
||||
$schedule->command('gc:failedjobs')->dailyAt(3)->onOneServer();
|
||||
$schedule->command('gc:passwordreset')->dailyAt('09:41')->onOneServer();
|
||||
$schedule->command('gc:sessions')->twiceDaily(13, 23)->onOneServer();
|
||||
|
||||
if(in_array(config_cache('pixelfed.cloud_storage'), ['1', true, 'true']) && config('media.delete_local_after_cloud')) {
|
||||
if ((bool) config_cache('pixelfed.cloud_storage') && (bool) config_cache('media.delete_local_after_cloud')) {
|
||||
$schedule->command('media:s3gc')->hourlyAt(15);
|
||||
}
|
||||
|
||||
if(config('import.instagram.enabled')) {
|
||||
$schedule->command('app:transform-imports')->everyTenMinutes();
|
||||
$schedule->command('app:import-upload-garbage-collection')->hourlyAt(51);
|
||||
$schedule->command('app:import-remove-deleted-accounts')->hourlyAt(37);
|
||||
$schedule->command('app:import-upload-clean-storage')->twiceDailyAt(1, 13, 32);
|
||||
if (config('import.instagram.enabled')) {
|
||||
$schedule->command('app:transform-imports')->everyTenMinutes()->onOneServer();
|
||||
$schedule->command('app:import-upload-garbage-collection')->hourlyAt(51)->onOneServer();
|
||||
$schedule->command('app:import-remove-deleted-accounts')->hourlyAt(37)->onOneServer();
|
||||
$schedule->command('app:import-upload-clean-storage')->twiceDailyAt(1, 13, 32)->onOneServer();
|
||||
|
||||
if(config('import.instagram.storage.cloud.enabled') && (bool) config_cache('pixelfed.cloud_storage')) {
|
||||
$schedule->command('app:import-upload-media-to-cloud-storage')->hourlyAt(39);
|
||||
if (config('import.instagram.storage.cloud.enabled') && (bool) config_cache('pixelfed.cloud_storage')) {
|
||||
$schedule->command('app:import-upload-media-to-cloud-storage')->hourlyAt(39)->onOneServer();
|
||||
}
|
||||
}
|
||||
$schedule->command('app:notification-epoch-update')->weeklyOn(1, '2:21');
|
||||
$schedule->command('app:hashtag-cached-count-update')->hourlyAt(25);
|
||||
$schedule->command('app:account-post-count-stat-update')->everySixHours(25);
|
||||
|
||||
$schedule->command('app:notification-epoch-update')->weeklyOn(1, '2:21')->onOneServer();
|
||||
$schedule->command('app:hashtag-cached-count-update')->hourlyAt(25)->onOneServer();
|
||||
$schedule->command('app:account-post-count-stat-update')->everySixHours(25)->onOneServer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +60,7 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ class AccountController extends Controller
|
|||
|
||||
$pid = $request->user()->profile_id;
|
||||
$count = UserFilterService::muteCount($pid);
|
||||
$maxLimit = intval(config('instance.user_filters.max_user_mutes'));
|
||||
$maxLimit = (int) config_cache('instance.user_filters.max_user_mutes');
|
||||
abort_if($count >= $maxLimit, 422, self::FILTER_LIMIT_MUTE_TEXT . $maxLimit . ' accounts');
|
||||
if($count == 0) {
|
||||
$filterCount = UserFilter::whereUserId($pid)->count();
|
||||
|
@ -260,7 +260,7 @@ class AccountController extends Controller
|
|||
]);
|
||||
$pid = $request->user()->profile_id;
|
||||
$count = UserFilterService::blockCount($pid);
|
||||
$maxLimit = intval(config('instance.user_filters.max_user_blocks'));
|
||||
$maxLimit = (int) config_cache('instance.user_filters.max_user_blocks');
|
||||
abort_if($count >= $maxLimit, 422, self::FILTER_LIMIT_BLOCK_TEXT . $maxLimit . ' accounts');
|
||||
if($count == 0) {
|
||||
$filterCount = UserFilter::whereUserId($pid)->whereFilterType('block')->count();
|
||||
|
|
|
@ -2,30 +2,20 @@
|
|||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use DB, Cache;
|
||||
use App\{
|
||||
DiscoverCategory,
|
||||
DiscoverCategoryHashtag,
|
||||
Hashtag,
|
||||
Media,
|
||||
Profile,
|
||||
Status,
|
||||
StatusHashtag,
|
||||
User
|
||||
};
|
||||
use App\Http\Controllers\PixelfedDirectoryController;
|
||||
use App\Models\ConfigCache;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\ConfigCacheService;
|
||||
use App\Services\StatusService;
|
||||
use Carbon\Carbon;
|
||||
use App\Status;
|
||||
use App\User;
|
||||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use League\ISO3166\ISO3166;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Http\Controllers\PixelfedDirectoryController;
|
||||
use Illuminate\Support\Str;
|
||||
use League\ISO3166\ISO3166;
|
||||
|
||||
trait AdminDirectoryController
|
||||
{
|
||||
|
@ -41,40 +31,41 @@ trait AdminDirectoryController
|
|||
$res['countries'] = collect((new ISO3166)->all())->pluck('name');
|
||||
$res['admins'] = User::whereIsAdmin(true)
|
||||
->where('2fa_enabled', true)
|
||||
->get()->map(function($user) {
|
||||
return [
|
||||
'uid' => (string) $user->id,
|
||||
'pid' => (string) $user->profile_id,
|
||||
'username' => $user->username,
|
||||
'created_at' => $user->created_at
|
||||
];
|
||||
});
|
||||
->get()->map(function ($user) {
|
||||
return [
|
||||
'uid' => (string) $user->id,
|
||||
'pid' => (string) $user->profile_id,
|
||||
'username' => $user->username,
|
||||
'created_at' => $user->created_at,
|
||||
];
|
||||
});
|
||||
$config = ConfigCache::whereK('pixelfed.directory')->first();
|
||||
if($config) {
|
||||
if ($config) {
|
||||
$data = $config->v ? json_decode($config->v, true) : [];
|
||||
$res = array_merge($res, $data);
|
||||
}
|
||||
|
||||
if(empty($res['summary'])) {
|
||||
if (empty($res['summary'])) {
|
||||
$summary = ConfigCache::whereK('app.short_description')->pluck('v');
|
||||
$res['summary'] = $summary ? $summary[0] : null;
|
||||
}
|
||||
|
||||
if(isset($res['banner_image']) && !empty($res['banner_image'])) {
|
||||
if (isset($res['banner_image']) && ! empty($res['banner_image'])) {
|
||||
$res['banner_image'] = url(Storage::url($res['banner_image']));
|
||||
}
|
||||
|
||||
if(isset($res['favourite_posts'])) {
|
||||
$res['favourite_posts'] = collect($res['favourite_posts'])->map(function($id) {
|
||||
if (isset($res['favourite_posts'])) {
|
||||
$res['favourite_posts'] = collect($res['favourite_posts'])->map(function ($id) {
|
||||
return StatusService::get($id);
|
||||
})
|
||||
->filter(function($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
->filter(function ($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
}
|
||||
|
||||
$res['community_guidelines'] = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : [];
|
||||
$res['curated_onboarding'] = (bool) config_cache('instance.curated_registration.enabled');
|
||||
$res['open_registration'] = (bool) config_cache('pixelfed.open_registration');
|
||||
$res['oauth_enabled'] = (bool) config_cache('pixelfed.oauth_enabled') && file_exists(storage_path('oauth-public.key')) && file_exists(storage_path('oauth-private.key'));
|
||||
|
||||
|
@ -83,22 +74,22 @@ trait AdminDirectoryController
|
|||
$res['feature_config'] = [
|
||||
'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','),
|
||||
'image_quality' => config_cache('pixelfed.image_quality'),
|
||||
'optimize_image' => config_cache('pixelfed.optimize_image'),
|
||||
'optimize_image' => (bool) config_cache('pixelfed.optimize_image'),
|
||||
'max_photo_size' => config_cache('pixelfed.max_photo_size'),
|
||||
'max_caption_length' => config_cache('pixelfed.max_caption_length'),
|
||||
'max_altext_length' => config_cache('pixelfed.max_altext_length'),
|
||||
'enforce_account_limit' => config_cache('pixelfed.enforce_account_limit'),
|
||||
'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit'),
|
||||
'max_account_size' => config_cache('pixelfed.max_account_size'),
|
||||
'max_album_length' => config_cache('pixelfed.max_album_length'),
|
||||
'account_deletion' => config_cache('pixelfed.account_deletion'),
|
||||
'account_deletion' => (bool) config_cache('pixelfed.account_deletion'),
|
||||
];
|
||||
|
||||
if(config_cache('pixelfed.directory.testimonials')) {
|
||||
$testimonials = collect(json_decode(config_cache('pixelfed.directory.testimonials'),true))
|
||||
->map(function($t) {
|
||||
if (config_cache('pixelfed.directory.testimonials')) {
|
||||
$testimonials = collect(json_decode(config_cache('pixelfed.directory.testimonials'), true))
|
||||
->map(function ($t) {
|
||||
return [
|
||||
'profile' => AccountService::get($t['profile_id']),
|
||||
'body' => $t['body']
|
||||
'body' => $t['body'],
|
||||
];
|
||||
});
|
||||
$res['testimonials'] = $testimonials;
|
||||
|
@ -107,8 +98,8 @@ trait AdminDirectoryController
|
|||
$validator = Validator::make($res['feature_config'], [
|
||||
'media_types' => [
|
||||
'required',
|
||||
function ($attribute, $value, $fail) {
|
||||
if (!in_array('image/jpeg', $value->toArray()) || !in_array('image/png', $value->toArray())) {
|
||||
function ($attribute, $value, $fail) {
|
||||
if (! in_array('image/jpeg', $value->toArray()) || ! in_array('image/png', $value->toArray())) {
|
||||
$fail('You must enable image/jpeg and image/png support.');
|
||||
}
|
||||
},
|
||||
|
@ -119,12 +110,12 @@ trait AdminDirectoryController
|
|||
'max_account_size' => 'required_if:enforce_account_limit,true|integer|min:1000000',
|
||||
'max_album_length' => 'required|integer|min:4|max:20',
|
||||
'account_deletion' => 'required|accepted',
|
||||
'max_caption_length' => 'required|integer|min:500|max:10000'
|
||||
'max_caption_length' => 'required|integer|min:500|max:10000',
|
||||
]);
|
||||
|
||||
$res['requirements_validator'] = $validator->errors();
|
||||
|
||||
$res['is_eligible'] = $res['open_registration'] &&
|
||||
$res['is_eligible'] = ($res['open_registration'] || $res['curated_onboarding']) &&
|
||||
$res['oauth_enabled'] &&
|
||||
$res['activitypub_enabled'] &&
|
||||
count($res['requirements_validator']) === 0 &&
|
||||
|
@ -145,11 +136,11 @@ trait AdminDirectoryController
|
|||
foreach (new \DirectoryIterator($path) as $io) {
|
||||
$name = $io->getFilename();
|
||||
$skip = ['vendor'];
|
||||
if($io->isDot() || in_array($name, $skip)) {
|
||||
if ($io->isDot() || in_array($name, $skip)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($io->isDir()) {
|
||||
if ($io->isDir()) {
|
||||
$langs->push(['code' => $name, 'name' => locale_get_display_name($name)]);
|
||||
}
|
||||
}
|
||||
|
@ -158,25 +149,26 @@ trait AdminDirectoryController
|
|||
$res['primary_locale'] = config('app.locale');
|
||||
|
||||
$submissionState = Http::withoutVerifying()
|
||||
->post('https://pixelfed.org/api/v1/directory/check-submission', [
|
||||
'domain' => config('pixelfed.domain.app')
|
||||
]);
|
||||
->post('https://pixelfed.org/api/v1/directory/check-submission', [
|
||||
'domain' => config('pixelfed.domain.app'),
|
||||
]);
|
||||
|
||||
$res['submission_state'] = $submissionState->json();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function validVal($res, $val, $count = false, $minLen = false)
|
||||
{
|
||||
if(!isset($res[$val])) {
|
||||
if (! isset($res[$val])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($count) {
|
||||
if ($count) {
|
||||
return count($res[$val]) >= $count;
|
||||
}
|
||||
|
||||
if($minLen) {
|
||||
if ($minLen) {
|
||||
return strlen($res[$val]) >= $minLen;
|
||||
}
|
||||
|
||||
|
@ -193,11 +185,11 @@ trait AdminDirectoryController
|
|||
'favourite_posts' => 'array|max:12',
|
||||
'favourite_posts.*' => 'distinct',
|
||||
'privacy_pledge' => 'sometimes',
|
||||
'banner_image' => 'sometimes|mimes:jpg,png|dimensions:width=1920,height:1080|max:5000'
|
||||
'banner_image' => 'sometimes|mimes:jpg,png|dimensions:width=1920,height:1080|max:5000',
|
||||
]);
|
||||
|
||||
$config = ConfigCache::firstOrNew([
|
||||
'k' => 'pixelfed.directory'
|
||||
'k' => 'pixelfed.directory',
|
||||
]);
|
||||
|
||||
$res = $config->v ? json_decode($config->v, true) : [];
|
||||
|
@ -207,27 +199,28 @@ trait AdminDirectoryController
|
|||
$res['contact_email'] = $request->input('contact_email');
|
||||
$res['privacy_pledge'] = (bool) $request->input('privacy_pledge');
|
||||
|
||||
if($request->filled('location')) {
|
||||
if ($request->filled('location')) {
|
||||
$exists = (new ISO3166)->name($request->location);
|
||||
if($exists) {
|
||||
if ($exists) {
|
||||
$res['location'] = $request->input('location');
|
||||
}
|
||||
}
|
||||
|
||||
if($request->hasFile('banner_image')) {
|
||||
if ($request->hasFile('banner_image')) {
|
||||
collect(Storage::files('public/headers'))
|
||||
->filter(function($name) {
|
||||
$protected = [
|
||||
'public/headers/.gitignore',
|
||||
'public/headers/default.jpg',
|
||||
'public/headers/missing.png'
|
||||
];
|
||||
return !in_array($name, $protected);
|
||||
})
|
||||
->each(function($name) {
|
||||
Storage::delete($name);
|
||||
});
|
||||
$path = $request->file('banner_image')->store('public/headers');
|
||||
->filter(function ($name) {
|
||||
$protected = [
|
||||
'public/headers/.gitignore',
|
||||
'public/headers/default.jpg',
|
||||
'public/headers/missing.png',
|
||||
];
|
||||
|
||||
return ! in_array($name, $protected);
|
||||
})
|
||||
->each(function ($name) {
|
||||
Storage::delete($name);
|
||||
});
|
||||
$path = $request->file('banner_image')->storePublicly('public/headers');
|
||||
$res['banner_image'] = $path;
|
||||
ConfigCacheService::put('app.banner_image', url(Storage::url($path)));
|
||||
|
||||
|
@ -239,9 +232,10 @@ trait AdminDirectoryController
|
|||
|
||||
ConfigCacheService::put('pixelfed.directory', $config->v);
|
||||
$updated = json_decode($config->v, true);
|
||||
if(isset($updated['banner_image'])) {
|
||||
if (isset($updated['banner_image'])) {
|
||||
$updated['banner_image'] = url(Storage::url($updated['banner_image']));
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
|
@ -249,9 +243,10 @@ trait AdminDirectoryController
|
|||
{
|
||||
$reqs = [];
|
||||
$reqs['feature_config'] = [
|
||||
'open_registration' => config_cache('pixelfed.open_registration'),
|
||||
'open_registration' => (bool) config_cache('pixelfed.open_registration'),
|
||||
'curated_onboarding' => (bool) config_cache('instance.curated_registration.enabled'),
|
||||
'activitypub_enabled' => config_cache('federation.activitypub.enabled'),
|
||||
'oauth_enabled' => config_cache('pixelfed.oauth_enabled'),
|
||||
'oauth_enabled' => (bool) config_cache('pixelfed.oauth_enabled'),
|
||||
'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','),
|
||||
'image_quality' => config_cache('pixelfed.image_quality'),
|
||||
'optimize_image' => config_cache('pixelfed.optimize_image'),
|
||||
|
@ -265,13 +260,14 @@ trait AdminDirectoryController
|
|||
];
|
||||
|
||||
$validator = Validator::make($reqs['feature_config'], [
|
||||
'open_registration' => 'required|accepted',
|
||||
'open_registration' => 'required_unless:curated_onboarding,true',
|
||||
'curated_onboarding' => 'required_unless:open_registration,true',
|
||||
'activitypub_enabled' => 'required|accepted',
|
||||
'oauth_enabled' => 'required|accepted',
|
||||
'media_types' => [
|
||||
'required',
|
||||
function ($attribute, $value, $fail) {
|
||||
if (!in_array('image/jpeg', $value->toArray()) || !in_array('image/png', $value->toArray())) {
|
||||
function ($attribute, $value, $fail) {
|
||||
if (! in_array('image/jpeg', $value->toArray()) || ! in_array('image/png', $value->toArray())) {
|
||||
$fail('You must enable image/jpeg and image/png support.');
|
||||
}
|
||||
},
|
||||
|
@ -282,10 +278,10 @@ trait AdminDirectoryController
|
|||
'max_account_size' => 'required_if:enforce_account_limit,true|integer|min:1000000',
|
||||
'max_album_length' => 'required|integer|min:4|max:20',
|
||||
'account_deletion' => 'required|accepted',
|
||||
'max_caption_length' => 'required|integer|min:500|max:10000'
|
||||
'max_caption_length' => 'required|integer|min:500|max:10000',
|
||||
]);
|
||||
|
||||
if(!$validator->validate()) {
|
||||
if (! $validator->validate()) {
|
||||
return response()->json($validator->errors(), 422);
|
||||
}
|
||||
|
||||
|
@ -294,6 +290,7 @@ trait AdminDirectoryController
|
|||
|
||||
$data = (new PixelfedDirectoryController())->buildListing();
|
||||
$res = Http::withoutVerifying()->post('https://pixelfed.org/api/v1/directory/submission', $data);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
@ -301,7 +298,7 @@ trait AdminDirectoryController
|
|||
{
|
||||
$bannerImage = ConfigCache::whereK('app.banner_image')->first();
|
||||
$directory = ConfigCache::whereK('pixelfed.directory')->first();
|
||||
if(!$bannerImage && !$directory || empty($directory->v)) {
|
||||
if (! $bannerImage && ! $directory || empty($directory->v)) {
|
||||
return;
|
||||
}
|
||||
$directoryArr = json_decode($directory->v, true);
|
||||
|
@ -309,12 +306,12 @@ trait AdminDirectoryController
|
|||
$protected = [
|
||||
'public/headers/.gitignore',
|
||||
'public/headers/default.jpg',
|
||||
'public/headers/missing.png'
|
||||
'public/headers/missing.png',
|
||||
];
|
||||
if(!$path || in_array($path, $protected)) {
|
||||
if (! $path || in_array($path, $protected)) {
|
||||
return;
|
||||
}
|
||||
if(Storage::exists($directoryArr['banner_image'])) {
|
||||
if (Storage::exists($directoryArr['banner_image'])) {
|
||||
Storage::delete($directoryArr['banner_image']);
|
||||
}
|
||||
|
||||
|
@ -325,12 +322,13 @@ trait AdminDirectoryController
|
|||
$bannerImage->save();
|
||||
Cache::forget('api:v1:instance-data-response-v1');
|
||||
ConfigCacheService::put('pixelfed.directory', $directory);
|
||||
|
||||
return $bannerImage->v;
|
||||
}
|
||||
|
||||
public function directoryGetPopularPosts(Request $request)
|
||||
{
|
||||
$ids = Cache::remember('admin:api:popular_posts', 86400, function() {
|
||||
$ids = Cache::remember('admin:api:popular_posts', 86400, function () {
|
||||
return Status::whereLocal(true)
|
||||
->whereScope('public')
|
||||
->whereType('photo')
|
||||
|
@ -340,21 +338,21 @@ trait AdminDirectoryController
|
|||
->pluck('id');
|
||||
});
|
||||
|
||||
$res = $ids->map(function($id) {
|
||||
$res = $ids->map(function ($id) {
|
||||
return StatusService::get($id);
|
||||
})
|
||||
->filter(function($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
->filter(function ($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
public function directoryGetAddPostByIdSearch(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'q' => 'required|integer'
|
||||
'q' => 'required|integer',
|
||||
]);
|
||||
|
||||
$id = $request->input('q');
|
||||
|
@ -377,11 +375,12 @@ trait AdminDirectoryController
|
|||
$profile_id = $request->input('profile_id');
|
||||
$testimonials = ConfigCache::whereK('pixelfed.directory.testimonials')->firstOrFail();
|
||||
$existing = collect(json_decode($testimonials->v, true))
|
||||
->filter(function($t) use($profile_id) {
|
||||
->filter(function ($t) use ($profile_id) {
|
||||
return $t['profile_id'] !== $profile_id;
|
||||
})
|
||||
->values();
|
||||
ConfigCacheService::put('pixelfed.directory.testimonials', $existing);
|
||||
|
||||
return $existing;
|
||||
}
|
||||
|
||||
|
@ -389,13 +388,13 @@ trait AdminDirectoryController
|
|||
{
|
||||
$this->validate($request, [
|
||||
'username' => 'required',
|
||||
'body' => 'required|string|min:5|max:500'
|
||||
'body' => 'required|string|min:5|max:500',
|
||||
]);
|
||||
|
||||
$user = User::whereUsername($request->input('username'))->whereNull('status')->firstOrFail();
|
||||
|
||||
$configCache = ConfigCache::firstOrCreate([
|
||||
'k' => 'pixelfed.directory.testimonials'
|
||||
'k' => 'pixelfed.directory.testimonials',
|
||||
]);
|
||||
|
||||
$testimonials = $configCache->v ? collect(json_decode($configCache->v, true)) : collect([]);
|
||||
|
@ -406,7 +405,7 @@ trait AdminDirectoryController
|
|||
$testimonials->push([
|
||||
'profile_id' => (string) $user->profile_id,
|
||||
'username' => $request->input('username'),
|
||||
'body' => $request->input('body')
|
||||
'body' => $request->input('body'),
|
||||
]);
|
||||
|
||||
$configCache->v = json_encode($testimonials->toArray());
|
||||
|
@ -414,8 +413,9 @@ trait AdminDirectoryController
|
|||
ConfigCacheService::put('pixelfed.directory.testimonials', $configCache->v);
|
||||
$res = [
|
||||
'profile' => AccountService::get($user->profile_id),
|
||||
'body' => $request->input('body')
|
||||
'body' => $request->input('body'),
|
||||
];
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -423,7 +423,7 @@ trait AdminDirectoryController
|
|||
{
|
||||
$this->validate($request, [
|
||||
'profile_id' => 'required',
|
||||
'body' => 'required|string|min:5|max:500'
|
||||
'body' => 'required|string|min:5|max:500',
|
||||
]);
|
||||
|
||||
$profile_id = $request->input('profile_id');
|
||||
|
@ -431,18 +431,19 @@ trait AdminDirectoryController
|
|||
$user = User::whereProfileId($profile_id)->firstOrFail();
|
||||
|
||||
$configCache = ConfigCache::firstOrCreate([
|
||||
'k' => 'pixelfed.directory.testimonials'
|
||||
'k' => 'pixelfed.directory.testimonials',
|
||||
]);
|
||||
|
||||
$testimonials = $configCache->v ? collect(json_decode($configCache->v, true)) : collect([]);
|
||||
|
||||
$updated = $testimonials->map(function($t) use($profile_id, $body) {
|
||||
if($t['profile_id'] == $profile_id) {
|
||||
$updated = $testimonials->map(function ($t) use ($profile_id, $body) {
|
||||
if ($t['profile_id'] == $profile_id) {
|
||||
$t['body'] = $body;
|
||||
}
|
||||
|
||||
return $t;
|
||||
})
|
||||
->values();
|
||||
->values();
|
||||
|
||||
$configCache->v = json_encode($updated);
|
||||
$configCache->save();
|
||||
|
|
Plik diff jest za duży
Load Diff
Plik diff jest za duży
Load Diff
|
@ -424,7 +424,7 @@ class AdminController extends Controller
|
|||
|
||||
public function customEmojiHome(Request $request)
|
||||
{
|
||||
if(!config('federation.custom_emoji.enabled')) {
|
||||
if(!(bool) config_cache('federation.custom_emoji.enabled')) {
|
||||
return view('admin.custom-emoji.not-enabled');
|
||||
}
|
||||
$this->validate($request, [
|
||||
|
@ -497,7 +497,7 @@ class AdminController extends Controller
|
|||
|
||||
public function customEmojiToggleActive(Request $request, $id)
|
||||
{
|
||||
abort_unless(config('federation.custom_emoji.enabled'), 404);
|
||||
abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404);
|
||||
$emoji = CustomEmoji::findOrFail($id);
|
||||
$emoji->disabled = !$emoji->disabled;
|
||||
$emoji->save();
|
||||
|
@ -508,13 +508,13 @@ class AdminController extends Controller
|
|||
|
||||
public function customEmojiAdd(Request $request)
|
||||
{
|
||||
abort_unless(config('federation.custom_emoji.enabled'), 404);
|
||||
abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404);
|
||||
return view('admin.custom-emoji.add');
|
||||
}
|
||||
|
||||
public function customEmojiStore(Request $request)
|
||||
{
|
||||
abort_unless(config('federation.custom_emoji.enabled'), 404);
|
||||
abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404);
|
||||
$this->validate($request, [
|
||||
'shortcode' => [
|
||||
'required',
|
||||
|
@ -545,7 +545,7 @@ class AdminController extends Controller
|
|||
|
||||
public function customEmojiDelete(Request $request, $id)
|
||||
{
|
||||
abort_unless(config('federation.custom_emoji.enabled'), 404);
|
||||
abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404);
|
||||
$emoji = CustomEmoji::findOrFail($id);
|
||||
Storage::delete("public/{$emoji->media_path}");
|
||||
Cache::forget('pf:custom_emoji');
|
||||
|
@ -555,7 +555,7 @@ class AdminController extends Controller
|
|||
|
||||
public function customEmojiShowDuplicates(Request $request, $id)
|
||||
{
|
||||
abort_unless(config('federation.custom_emoji.enabled'), 404);
|
||||
abort_unless((bool) config_cache('federation.custom_emoji.enabled'), 404);
|
||||
$emoji = CustomEmoji::orderBy('id')->whereDisabled(false)->whereShortcode($id)->firstOrFail();
|
||||
$emojis = CustomEmoji::whereShortcode($id)->where('id', '!=', $emoji->id)->cursorPaginate(10);
|
||||
return view('admin.custom-emoji.duplicates', compact('emoji', 'emojis'));
|
||||
|
|
|
@ -0,0 +1,335 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Mail\CuratedRegisterAcceptUser;
|
||||
use App\Mail\CuratedRegisterRejectUser;
|
||||
use App\Mail\CuratedRegisterRequestDetailsFromUser;
|
||||
use App\Models\CuratedRegister;
|
||||
use App\Models\CuratedRegisterActivity;
|
||||
use App\Models\CuratedRegisterTemplate;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class AdminCuratedRegisterController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['auth', 'admin']);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'filter' => 'sometimes|in:open,all,awaiting,approved,rejected,responses',
|
||||
'sort' => 'sometimes|in:asc,desc',
|
||||
]);
|
||||
$filter = $request->input('filter', 'open');
|
||||
$sort = $request->input('sort', 'asc');
|
||||
$records = CuratedRegister::when($filter, function ($q, $filter) {
|
||||
if ($filter === 'open') {
|
||||
return $q->where('is_rejected', false)
|
||||
->where(function ($query) {
|
||||
return $query->where('user_has_responded', true)->orWhere('is_awaiting_more_info', false);
|
||||
})
|
||||
->whereNotNull('email_verified_at')
|
||||
->whereIsClosed(false);
|
||||
} elseif ($filter === 'all') {
|
||||
return $q;
|
||||
} elseif ($filter === 'responses') {
|
||||
return $q->whereIsClosed(false)
|
||||
->whereNotNull('email_verified_at')
|
||||
->where('user_has_responded', true)
|
||||
->where('is_awaiting_more_info', true);
|
||||
} elseif ($filter === 'awaiting') {
|
||||
return $q->whereIsClosed(false)
|
||||
->where('is_rejected', false)
|
||||
->where('is_approved', false)
|
||||
->where('user_has_responded', false)
|
||||
->where('is_awaiting_more_info', true);
|
||||
} elseif ($filter === 'approved') {
|
||||
return $q->whereIsClosed(true)->whereIsApproved(true);
|
||||
} elseif ($filter === 'rejected') {
|
||||
return $q->whereIsClosed(true)->whereIsRejected(true);
|
||||
}
|
||||
})
|
||||
->when($sort, function ($query, $sort) {
|
||||
return $query->orderBy('id', $sort);
|
||||
})
|
||||
->paginate(10)
|
||||
->withQueryString();
|
||||
|
||||
return view('admin.curated-register.index', compact('records', 'filter'));
|
||||
}
|
||||
|
||||
public function show(Request $request, $id)
|
||||
{
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
|
||||
return view('admin.curated-register.show', compact('record'));
|
||||
}
|
||||
|
||||
public function apiActivityLog(Request $request, $id)
|
||||
{
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
|
||||
$res = collect([
|
||||
[
|
||||
'id' => 1,
|
||||
'action' => 'created',
|
||||
'title' => 'Onboarding application created',
|
||||
'message' => null,
|
||||
'link' => null,
|
||||
'timestamp' => $record->created_at,
|
||||
],
|
||||
]);
|
||||
|
||||
if ($record->email_verified_at) {
|
||||
$res->push([
|
||||
'id' => 3,
|
||||
'action' => 'email_verified_at',
|
||||
'title' => 'Applicant successfully verified email address',
|
||||
'message' => null,
|
||||
'link' => null,
|
||||
'timestamp' => $record->email_verified_at,
|
||||
]);
|
||||
}
|
||||
|
||||
$activities = CuratedRegisterActivity::whereRegisterId($record->id)->get();
|
||||
|
||||
$idx = 4;
|
||||
$userResponses = collect([]);
|
||||
|
||||
foreach ($activities as $activity) {
|
||||
$idx++;
|
||||
|
||||
if ($activity->type === 'user_resend_email_confirmation') {
|
||||
continue;
|
||||
}
|
||||
if ($activity->from_user) {
|
||||
$userResponses->push($activity);
|
||||
|
||||
continue;
|
||||
}
|
||||
$res->push([
|
||||
'id' => $idx,
|
||||
'aid' => $activity->id,
|
||||
'action' => $activity->type,
|
||||
'title' => $activity->from_admin ? 'Admin requested info' : 'User responded',
|
||||
'message' => $activity->message,
|
||||
'link' => $activity->adminReviewUrl(),
|
||||
'timestamp' => $activity->created_at,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($userResponses as $ur) {
|
||||
$res = $res->map(function ($r) use ($ur) {
|
||||
if (! isset($r['aid'])) {
|
||||
return $r;
|
||||
}
|
||||
if ($ur->reply_to_id === $r['aid']) {
|
||||
$r['user_response'] = $ur;
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
return $r;
|
||||
});
|
||||
}
|
||||
|
||||
if ($record->is_approved) {
|
||||
$idx++;
|
||||
$res->push([
|
||||
'id' => $idx,
|
||||
'action' => 'approved',
|
||||
'title' => 'Application Approved',
|
||||
'message' => null,
|
||||
'link' => null,
|
||||
'timestamp' => $record->action_taken_at,
|
||||
]);
|
||||
} elseif ($record->is_rejected) {
|
||||
$idx++;
|
||||
$res->push([
|
||||
'id' => $idx,
|
||||
'action' => 'rejected',
|
||||
'title' => 'Application Rejected',
|
||||
'message' => null,
|
||||
'link' => null,
|
||||
'timestamp' => $record->action_taken_at,
|
||||
]);
|
||||
}
|
||||
|
||||
return $res->reverse()->values();
|
||||
}
|
||||
|
||||
public function apiMessagePreviewStore(Request $request, $id)
|
||||
{
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
|
||||
return $request->all();
|
||||
}
|
||||
|
||||
public function apiMessageSendStore(Request $request, $id)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'message' => 'required|string|min:5|max:3000',
|
||||
]);
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
abort_if($record->email_verified_at === null, 400, 'Cannot message an unverified email');
|
||||
$activity = new CuratedRegisterActivity;
|
||||
$activity->register_id = $record->id;
|
||||
$activity->admin_id = $request->user()->id;
|
||||
$activity->secret_code = Str::random(32);
|
||||
$activity->type = 'request_details';
|
||||
$activity->from_admin = true;
|
||||
$activity->message = $request->input('message');
|
||||
$activity->save();
|
||||
$record->is_awaiting_more_info = true;
|
||||
$record->user_has_responded = false;
|
||||
$record->save();
|
||||
Mail::to($record->email)->send(new CuratedRegisterRequestDetailsFromUser($record, $activity));
|
||||
|
||||
return $request->all();
|
||||
}
|
||||
|
||||
public function previewDetailsMessageShow(Request $request, $id)
|
||||
{
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
abort_if($record->email_verified_at === null, 400, 'Cannot message an unverified email');
|
||||
$activity = new CuratedRegisterActivity;
|
||||
$activity->message = $request->input('message');
|
||||
|
||||
return new \App\Mail\CuratedRegisterRequestDetailsFromUser($record, $activity);
|
||||
}
|
||||
|
||||
public function previewMessageShow(Request $request, $id)
|
||||
{
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
abort_if($record->email_verified_at === null, 400, 'Cannot message an unverified email');
|
||||
$record->message = $request->input('message');
|
||||
|
||||
return new \App\Mail\CuratedRegisterSendMessage($record);
|
||||
}
|
||||
|
||||
public function apiHandleReject(Request $request, $id)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'action' => 'required|in:reject-email,reject-silent',
|
||||
]);
|
||||
$action = $request->input('action');
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
abort_if($record->email_verified_at === null, 400, 'Cannot reject an unverified email');
|
||||
$record->is_rejected = true;
|
||||
$record->is_closed = true;
|
||||
$record->action_taken_at = now();
|
||||
$record->save();
|
||||
if ($action === 'reject-email') {
|
||||
Mail::to($record->email)->send(new CuratedRegisterRejectUser($record));
|
||||
}
|
||||
|
||||
return [200];
|
||||
}
|
||||
|
||||
public function apiHandleApprove(Request $request, $id)
|
||||
{
|
||||
$record = CuratedRegister::findOrFail($id);
|
||||
abort_if($record->email_verified_at === null, 400, 'Cannot reject an unverified email');
|
||||
$record->is_approved = true;
|
||||
$record->is_closed = true;
|
||||
$record->action_taken_at = now();
|
||||
$record->save();
|
||||
$user = User::create([
|
||||
'name' => $record->username,
|
||||
'username' => $record->username,
|
||||
'email' => $record->email,
|
||||
'password' => $record->password,
|
||||
'app_register_ip' => $record->ip_address,
|
||||
'email_verified_at' => now(),
|
||||
'register_source' => 'cur_onboarding',
|
||||
]);
|
||||
|
||||
Mail::to($record->email)->send(new CuratedRegisterAcceptUser($record));
|
||||
|
||||
return [200];
|
||||
}
|
||||
|
||||
public function templates(Request $request)
|
||||
{
|
||||
$templates = CuratedRegisterTemplate::paginate(10);
|
||||
|
||||
return view('admin.curated-register.templates', compact('templates'));
|
||||
}
|
||||
|
||||
public function templateCreate(Request $request)
|
||||
{
|
||||
return view('admin.curated-register.template-create');
|
||||
}
|
||||
|
||||
public function templateEdit(Request $request, $id)
|
||||
{
|
||||
$template = CuratedRegisterTemplate::findOrFail($id);
|
||||
|
||||
return view('admin.curated-register.template-edit', compact('template'));
|
||||
}
|
||||
|
||||
public function templateEditStore(Request $request, $id)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'name' => 'required|string|max:30',
|
||||
'content' => 'required|string|min:5|max:3000',
|
||||
'description' => 'nullable|sometimes|string|max:1000',
|
||||
'active' => 'sometimes',
|
||||
]);
|
||||
$template = CuratedRegisterTemplate::findOrFail($id);
|
||||
$template->name = $request->input('name');
|
||||
$template->content = $request->input('content');
|
||||
$template->description = $request->input('description');
|
||||
$template->is_active = $request->boolean('active');
|
||||
$template->save();
|
||||
|
||||
return redirect()->back()->with('status', 'Successfully updated template!');
|
||||
}
|
||||
|
||||
public function templateDelete(Request $request, $id)
|
||||
{
|
||||
$template = CuratedRegisterTemplate::findOrFail($id);
|
||||
$template->delete();
|
||||
|
||||
return redirect(route('admin.curated-onboarding.templates'))->with('status', 'Successfully deleted template!');
|
||||
}
|
||||
|
||||
public function templateStore(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'name' => 'required|string|max:30',
|
||||
'content' => 'required|string|min:5|max:3000',
|
||||
'description' => 'nullable|sometimes|string|max:1000',
|
||||
'active' => 'sometimes',
|
||||
]);
|
||||
CuratedRegisterTemplate::create([
|
||||
'name' => $request->input('name'),
|
||||
'content' => $request->input('content'),
|
||||
'description' => $request->input('description'),
|
||||
'is_active' => $request->boolean('active'),
|
||||
]);
|
||||
|
||||
return redirect(route('admin.curated-onboarding.templates'))->with('status', 'Successfully created new template!');
|
||||
}
|
||||
|
||||
public function getActiveTemplates(Request $request)
|
||||
{
|
||||
$templates = CuratedRegisterTemplate::whereIsActive(true)
|
||||
->orderBy('order')
|
||||
->get()
|
||||
->map(function ($tmp) {
|
||||
return [
|
||||
'name' => $tmp->name,
|
||||
'content' => $tmp->content,
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json($templates);
|
||||
}
|
||||
}
|
Plik diff jest za duży
Load Diff
Plik diff jest za duży
Load Diff
|
@ -71,72 +71,77 @@ class ApiV2Controller extends Controller
|
|||
->toArray() : [];
|
||||
});
|
||||
|
||||
$res = [
|
||||
'domain' => config('pixelfed.domain.app'),
|
||||
'title' => config_cache('app.name'),
|
||||
'version' => config('pixelfed.version'),
|
||||
'source_url' => 'https://github.com/pixelfed/pixelfed',
|
||||
'description' => config_cache('app.short_description'),
|
||||
'usage' => [
|
||||
'users' => [
|
||||
'active_month' => (int) Nodeinfo::activeUsersMonthly()
|
||||
]
|
||||
],
|
||||
'thumbnail' => [
|
||||
'url' => config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg')),
|
||||
'blurhash' => InstanceService::headerBlurhash(),
|
||||
'versions' => [
|
||||
'@1x' => config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg')),
|
||||
'@2x' => config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg'))
|
||||
]
|
||||
],
|
||||
'languages' => [config('app.locale')],
|
||||
'configuration' => [
|
||||
'urls' => [
|
||||
'streaming' => 'wss://' . config('pixelfed.domain.app'),
|
||||
'status' => null
|
||||
$res = Cache::remember('api:v2:instance-data-response-v2', 1800, function () use($contact, $rules) {
|
||||
return [
|
||||
'domain' => config('pixelfed.domain.app'),
|
||||
'title' => config_cache('app.name'),
|
||||
'version' => '3.5.3 (compatible; Pixelfed ' . config('pixelfed.version') .')',
|
||||
'source_url' => 'https://github.com/pixelfed/pixelfed',
|
||||
'description' => config_cache('app.short_description'),
|
||||
'usage' => [
|
||||
'users' => [
|
||||
'active_month' => (int) Nodeinfo::activeUsersMonthly()
|
||||
]
|
||||
],
|
||||
'vapid' => [
|
||||
'public_key' => config('webpush.vapid.public_key'),
|
||||
'thumbnail' => [
|
||||
'url' => config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg')),
|
||||
'blurhash' => InstanceService::headerBlurhash(),
|
||||
'versions' => [
|
||||
'@1x' => config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg')),
|
||||
'@2x' => config_cache('app.banner_image') ?? url(Storage::url('public/headers/default.jpg'))
|
||||
]
|
||||
],
|
||||
'accounts' => [
|
||||
'max_featured_tags' => 0,
|
||||
'languages' => [config('app.locale')],
|
||||
'configuration' => [
|
||||
'urls' => [
|
||||
'streaming' => null,
|
||||
'status' => null
|
||||
],
|
||||
'vapid' => [
|
||||
'public_key' => config('webpush.vapid.public_key'),
|
||||
],
|
||||
'accounts' => [
|
||||
'max_featured_tags' => 0,
|
||||
],
|
||||
'statuses' => [
|
||||
'max_characters' => (int) config_cache('pixelfed.max_caption_length'),
|
||||
'max_media_attachments' => (int) config_cache('pixelfed.max_album_length'),
|
||||
'characters_reserved_per_url' => 23
|
||||
],
|
||||
'media_attachments' => [
|
||||
'supported_mime_types' => explode(',', config_cache('pixelfed.media_types')),
|
||||
'image_size_limit' => config_cache('pixelfed.max_photo_size') * 1024,
|
||||
'image_matrix_limit' => 3686400,
|
||||
'video_size_limit' => config_cache('pixelfed.max_photo_size') * 1024,
|
||||
'video_frame_rate_limit' => 240,
|
||||
'video_matrix_limit' => 3686400
|
||||
],
|
||||
'polls' => [
|
||||
'max_options' => 0,
|
||||
'max_characters_per_option' => 0,
|
||||
'min_expiration' => 0,
|
||||
'max_expiration' => 0,
|
||||
],
|
||||
'translation' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
],
|
||||
'statuses' => [
|
||||
'max_characters' => (int) config('pixelfed.max_caption_length'),
|
||||
'max_media_attachments' => (int) config_cache('pixelfed.max_album_length'),
|
||||
'characters_reserved_per_url' => 23
|
||||
'registrations' => [
|
||||
'enabled' => null,
|
||||
'approval_required' => false,
|
||||
'message' => null,
|
||||
'url' => null,
|
||||
],
|
||||
'media_attachments' => [
|
||||
'supported_mime_types' => explode(',', config_cache('pixelfed.media_types')),
|
||||
'image_size_limit' => config_cache('pixelfed.max_photo_size') * 1024,
|
||||
'image_matrix_limit' => 3686400,
|
||||
'video_size_limit' => config_cache('pixelfed.max_photo_size') * 1024,
|
||||
'video_frame_rate_limit' => 240,
|
||||
'video_matrix_limit' => 3686400
|
||||
'contact' => [
|
||||
'email' => config('instance.email'),
|
||||
'account' => $contact
|
||||
],
|
||||
'polls' => [
|
||||
'max_options' => 4,
|
||||
'max_characters_per_option' => 50,
|
||||
'min_expiration' => 300,
|
||||
'max_expiration' => 2629746,
|
||||
],
|
||||
'translation' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
],
|
||||
'registrations' => [
|
||||
'enabled' => (bool) config_cache('pixelfed.open_registration'),
|
||||
'approval_required' => false,
|
||||
'message' => null
|
||||
],
|
||||
'contact' => [
|
||||
'email' => config('instance.email'),
|
||||
'account' => $contact
|
||||
],
|
||||
'rules' => $rules
|
||||
];
|
||||
'rules' => $rules
|
||||
];
|
||||
});
|
||||
|
||||
$res['registrations']['enabled'] = (bool) config_cache('pixelfed.open_registration');
|
||||
$res['registrations']['approval_required'] = (bool) config_cache('instance.curated_registration.enabled');
|
||||
return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ class DomainBlockController extends Controller
|
|||
abort_if(config_cache('pixelfed.domain.app') == $domain, 400, 'Cannot ban your own server');
|
||||
|
||||
$existingCount = UserDomainBlock::whereProfileId($pid)->count();
|
||||
$maxLimit = config('instance.user_filters.max_domain_blocks');
|
||||
$maxLimit = (int) config_cache('instance.user_filters.max_domain_blocks');
|
||||
$errorMsg = __('profile.block.domain.max', ['max' => $maxLimit]);
|
||||
|
||||
abort_if($existingCount >= $maxLimit, 400, $errorMsg);
|
||||
|
|
|
@ -62,7 +62,7 @@ class ForgotPasswordController extends Controller
|
|||
|
||||
usleep(random_int(100000, 3000000));
|
||||
|
||||
if(config('captcha.enabled')) {
|
||||
if((bool) config_cache('captcha.enabled')) {
|
||||
$rules = [
|
||||
'email' => 'required|email',
|
||||
'h-captcha-response' => 'required|captcha'
|
||||
|
|
|
@ -74,10 +74,10 @@ class LoginController extends Controller
|
|||
$messages = [];
|
||||
|
||||
if(
|
||||
config('captcha.enabled') ||
|
||||
config('captcha.active.login') ||
|
||||
(bool) config_cache('captcha.enabled') &&
|
||||
(bool) config_cache('captcha.active.login') ||
|
||||
(
|
||||
config('captcha.triggers.login.enabled') &&
|
||||
(bool) config_cache('captcha.triggers.login.enabled') &&
|
||||
request()->session()->has('login_attempts') &&
|
||||
request()->session()->get('login_attempts') >= config('captcha.triggers.login.attempts')
|
||||
)
|
||||
|
|
|
@ -137,7 +137,7 @@ class RegisterController extends Controller
|
|||
'password' => 'required|string|min:'.config('pixelfed.min_password_length').'|confirmed',
|
||||
];
|
||||
|
||||
if(config('captcha.enabled') || config('captcha.active.register')) {
|
||||
if((bool) config_cache('captcha.enabled') && (bool) config_cache('captcha.active.register')) {
|
||||
$rules['h-captcha-response'] = 'required|captcha';
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ class RegisterController extends Controller
|
|||
*/
|
||||
public function showRegistrationForm()
|
||||
{
|
||||
if(config_cache('pixelfed.open_registration')) {
|
||||
if((bool) config_cache('pixelfed.open_registration')) {
|
||||
if(config('pixelfed.bouncer.cloud_ips.ban_signups')) {
|
||||
abort_if(BouncerService::checkIp(request()->ip()), 404);
|
||||
}
|
||||
|
@ -191,7 +191,11 @@ class RegisterController extends Controller
|
|||
return view('auth.register');
|
||||
}
|
||||
} else {
|
||||
abort(404);
|
||||
if((bool) config_cache('instance.curated_registration.enabled') && config('instance.curated_registration.state.fallback_on_closed_reg')) {
|
||||
return redirect('/auth/sign_up');
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class ResetPasswordController extends Controller
|
|||
{
|
||||
usleep(random_int(100000, 3000000));
|
||||
|
||||
if(config('captcha.enabled')) {
|
||||
if((bool) config_cache('captcha.enabled')) {
|
||||
return [
|
||||
'token' => 'required',
|
||||
'email' => 'required|email',
|
||||
|
|
|
@ -2,23 +2,18 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Cache;
|
||||
|
||||
use App\Comment;
|
||||
use App\Jobs\CommentPipeline\CommentPipeline;
|
||||
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Profile;
|
||||
use App\Status;
|
||||
use App\UserFilter;
|
||||
use League\Fractal;
|
||||
use App\Transformer\Api\StatusTransformer;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\Transformer\Api\StatusTransformer;
|
||||
use App\UserFilter;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
|
@ -33,9 +28,9 @@ class CommentController extends Controller
|
|||
abort(403);
|
||||
}
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
'comment' => 'required|string|max:'.(int) config('pixelfed.max_caption_length'),
|
||||
'sensitive' => 'nullable|boolean'
|
||||
'item' => 'required|integer|min:1',
|
||||
'comment' => 'required|string|max:'.config_cache('pixelfed.max_caption_length'),
|
||||
'sensitive' => 'nullable|boolean',
|
||||
]);
|
||||
$comment = $request->input('comment');
|
||||
$statusId = $request->input('item');
|
||||
|
@ -45,7 +40,7 @@ class CommentController extends Controller
|
|||
$profile = $user->profile;
|
||||
$status = Status::findOrFail($statusId);
|
||||
|
||||
if($status->comments_disabled == true) {
|
||||
if ($status->comments_disabled == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -55,11 +50,11 @@ class CommentController extends Controller
|
|||
->whereFilterableId($profile->id)
|
||||
->exists();
|
||||
|
||||
if($filtered == true) {
|
||||
if ($filtered == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$reply = DB::transaction(function() use($comment, $status, $profile, $nsfw) {
|
||||
$reply = DB::transaction(function () use ($comment, $status, $profile, $nsfw) {
|
||||
$scope = $profile->is_private == true ? 'private' : 'public';
|
||||
$autolink = Autolink::create()->autolink($comment);
|
||||
$reply = new Status();
|
||||
|
|
|
@ -2,59 +2,38 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Auth, Cache, DB, Storage, URL;
|
||||
use Carbon\Carbon;
|
||||
use App\{
|
||||
Avatar,
|
||||
Collection,
|
||||
CollectionItem,
|
||||
Hashtag,
|
||||
Like,
|
||||
Media,
|
||||
MediaTag,
|
||||
Notification,
|
||||
Profile,
|
||||
Place,
|
||||
Status,
|
||||
UserFilter,
|
||||
UserSetting
|
||||
};
|
||||
use App\Models\Poll;
|
||||
use App\Transformer\Api\{
|
||||
MediaTransformer,
|
||||
MediaDraftTransformer,
|
||||
StatusTransformer,
|
||||
StatusStatelessTransformer
|
||||
};
|
||||
use League\Fractal;
|
||||
use App\Util\Media\Filter;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
use App\Jobs\AvatarPipeline\AvatarOptimize;
|
||||
use App\Collection;
|
||||
use App\CollectionItem;
|
||||
use App\Hashtag;
|
||||
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||
use App\Jobs\ImageOptimizePipeline\ImageThumbnail;
|
||||
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
||||
use App\Jobs\VideoPipeline\{
|
||||
VideoOptimize,
|
||||
VideoPostProcess,
|
||||
VideoThumbnail
|
||||
};
|
||||
use App\Jobs\VideoPipeline\VideoThumbnail;
|
||||
use App\Media;
|
||||
use App\MediaTag;
|
||||
use App\Models\Poll;
|
||||
use App\Notification;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\CollectionService;
|
||||
use App\Services\NotificationService;
|
||||
use App\Services\MediaPathService;
|
||||
use App\Services\MediaBlocklistService;
|
||||
use App\Services\MediaPathService;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Services\MediaTagService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\SnowflakeService;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Lexer\Extractor;
|
||||
use App\Util\Media\License;
|
||||
use Image;
|
||||
use App\Services\UserRoleService;
|
||||
use App\Status;
|
||||
use App\Transformer\Api\MediaTransformer;
|
||||
use App\UserFilter;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Media\Filter;
|
||||
use App\Util\Media\License;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
|
||||
class ComposeController extends Controller
|
||||
{
|
||||
|
@ -74,30 +53,30 @@ class ComposeController extends Controller
|
|||
|
||||
public function mediaUpload(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'file.*' => [
|
||||
'required_without:file',
|
||||
'mimetypes:' . config_cache('pixelfed.media_types'),
|
||||
'max:' . config_cache('pixelfed.max_photo_size'),
|
||||
'mimetypes:'.config_cache('pixelfed.media_types'),
|
||||
'max:'.config_cache('pixelfed.max_photo_size'),
|
||||
],
|
||||
'file' => [
|
||||
'required_without:file.*',
|
||||
'mimetypes:' . config_cache('pixelfed.media_types'),
|
||||
'max:' . config_cache('pixelfed.max_photo_size'),
|
||||
'mimetypes:'.config_cache('pixelfed.media_types'),
|
||||
'max:'.config_cache('pixelfed.max_photo_size'),
|
||||
],
|
||||
'filter_name' => 'nullable|string|max:24',
|
||||
'filter_class' => 'nullable|alpha_dash|max:24'
|
||||
'filter_class' => 'nullable|alpha_dash|max:24',
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-post', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-post', $user->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$limitKey = 'compose:rate-limit:media-upload:' . $user->id;
|
||||
$limitKey = 'compose:rate-limit:media-upload:'.$user->id;
|
||||
$limitTtl = now()->addMinutes(15);
|
||||
$limitReached = Cache::remember($limitKey, $limitTtl, function() use($user) {
|
||||
$limitReached = Cache::remember($limitKey, $limitTtl, function () use ($user) {
|
||||
$dailyLimit = Media::whereUserId($user->id)->where('created_at', '>', now()->subDays(1))->count();
|
||||
|
||||
return $dailyLimit >= 1250;
|
||||
|
@ -105,8 +84,8 @@ class ComposeController extends Controller
|
|||
|
||||
abort_if($limitReached == true, 429);
|
||||
|
||||
if(config_cache('pixelfed.enforce_account_limit') == true) {
|
||||
$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function() use($user) {
|
||||
if (config_cache('pixelfed.enforce_account_limit') == true) {
|
||||
$size = Cache::remember($user->storageUsedKey(), now()->addDays(3), function () use ($user) {
|
||||
return Media::whereUserId($user->id)->sum('size') / 1000;
|
||||
});
|
||||
$limit = (int) config_cache('pixelfed.max_account_size');
|
||||
|
@ -144,24 +123,24 @@ class ComposeController extends Controller
|
|||
$media->version = 3;
|
||||
$media->save();
|
||||
|
||||
$preview_url = $media->url() . '?v=' . time();
|
||||
$url = $media->url() . '?v=' . time();
|
||||
$preview_url = $media->url().'?v='.time();
|
||||
$url = $media->url().'?v='.time();
|
||||
|
||||
switch ($media->mime) {
|
||||
case 'image/jpeg':
|
||||
case 'image/png':
|
||||
case 'image/webp':
|
||||
ImageOptimize::dispatch($media)->onQueue('mmo');
|
||||
break;
|
||||
ImageOptimize::dispatch($media)->onQueue('mmo');
|
||||
break;
|
||||
|
||||
case 'video/mp4':
|
||||
VideoThumbnail::dispatch($media)->onQueue('mmo');
|
||||
$preview_url = '/storage/no-preview.png';
|
||||
$url = '/storage/no-preview.png';
|
||||
break;
|
||||
VideoThumbnail::dispatch($media)->onQueue('mmo');
|
||||
$preview_url = '/storage/no-preview.png';
|
||||
$url = '/storage/no-preview.png';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
Cache::forget($limitKey);
|
||||
|
@ -169,6 +148,7 @@ class ComposeController extends Controller
|
|||
$res = $this->fractal->createData($resource)->toArray();
|
||||
$res['preview_url'] = $preview_url;
|
||||
$res['url'] = $url;
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
|
@ -176,21 +156,21 @@ class ComposeController extends Controller
|
|||
{
|
||||
$this->validate($request, [
|
||||
'id' => 'required',
|
||||
'file' => function() {
|
||||
'file' => function () {
|
||||
return [
|
||||
'required',
|
||||
'mimetypes:' . config_cache('pixelfed.media_types'),
|
||||
'max:' . config_cache('pixelfed.max_photo_size'),
|
||||
'mimetypes:'.config_cache('pixelfed.media_types'),
|
||||
'max:'.config_cache('pixelfed.max_photo_size'),
|
||||
];
|
||||
},
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-post', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-post', $user->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$limitKey = 'compose:rate-limit:media-updates:' . $user->id;
|
||||
$limitKey = 'compose:rate-limit:media-updates:'.$user->id;
|
||||
$limitTtl = now()->addMinutes(15);
|
||||
$limitReached = Cache::remember($limitKey, $limitTtl, function() use($user) {
|
||||
$limitReached = Cache::remember($limitKey, $limitTtl, function () use ($user) {
|
||||
$dailyLimit = Media::whereUserId($user->id)->where('created_at', '>', now()->subDays(1))->count();
|
||||
|
||||
return $dailyLimit >= 1500;
|
||||
|
@ -202,9 +182,9 @@ class ComposeController extends Controller
|
|||
$id = $request->input('id');
|
||||
|
||||
$media = Media::whereUserId($user->id)
|
||||
->whereProfileId($user->profile_id)
|
||||
->whereNull('status_id')
|
||||
->findOrFail($id);
|
||||
->whereProfileId($user->profile_id)
|
||||
->whereNull('status_id')
|
||||
->findOrFail($id);
|
||||
|
||||
$media->save();
|
||||
|
||||
|
@ -214,47 +194,48 @@ class ComposeController extends Controller
|
|||
$dir = implode('/', $fragments);
|
||||
$path = $photo->storePubliclyAs($dir, $name);
|
||||
$res = [
|
||||
'url' => $media->url() . '?v=' . time()
|
||||
'url' => $media->url().'?v='.time(),
|
||||
];
|
||||
ImageOptimize::dispatch($media)->onQueue('mmo');
|
||||
Cache::forget($limitKey);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function mediaDelete(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'id' => 'required|integer|min:1|exists:media,id'
|
||||
'id' => 'required|integer|min:1|exists:media,id',
|
||||
]);
|
||||
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$media = Media::whereNull('status_id')
|
||||
->whereUserId(Auth::id())
|
||||
->findOrFail($request->input('id'));
|
||||
->whereUserId(Auth::id())
|
||||
->findOrFail($request->input('id'));
|
||||
|
||||
MediaStorageService::delete($media, true);
|
||||
|
||||
return response()->json([
|
||||
'msg' => 'Successfully deleted',
|
||||
'code' => 200
|
||||
'code' => 200,
|
||||
]);
|
||||
}
|
||||
|
||||
public function searchTag(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:1|max:50'
|
||||
'q' => 'required|string|min:1|max:50',
|
||||
]);
|
||||
|
||||
$q = $request->input('q');
|
||||
|
||||
if(Str::of($q)->startsWith('@')) {
|
||||
if(strlen($q) < 3) {
|
||||
if (Str::of($q)->startsWith('@')) {
|
||||
if (strlen($q) < 3) {
|
||||
return [];
|
||||
}
|
||||
$q = mb_substr($q, 1);
|
||||
|
@ -262,7 +243,7 @@ class ComposeController extends Controller
|
|||
|
||||
$user = $request->user();
|
||||
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-post', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-post', $user->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$blocked = UserFilter::whereFilterableType('App\Profile')
|
||||
->whereFilterType('block')
|
||||
|
@ -271,34 +252,34 @@ class ComposeController extends Controller
|
|||
|
||||
$blocked->push($request->user()->profile_id);
|
||||
|
||||
$results = Profile::select('id','domain','username')
|
||||
$results = Profile::select('id', 'domain', 'username')
|
||||
->whereNotIn('id', $blocked)
|
||||
->whereNull('domain')
|
||||
->where('username','like','%'.$q.'%')
|
||||
->where('username', 'like', '%'.$q.'%')
|
||||
->limit(15)
|
||||
->get()
|
||||
->map(function($r) {
|
||||
->map(function ($r) {
|
||||
return [
|
||||
'id' => (string) $r->id,
|
||||
'name' => $r->username,
|
||||
'privacy' => true,
|
||||
'avatar' => $r->avatarUrl()
|
||||
'avatar' => $r->avatarUrl(),
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function searchUntag(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'status_id' => 'required',
|
||||
'profile_id' => 'required'
|
||||
'profile_id' => 'required',
|
||||
]);
|
||||
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$user = $request->user();
|
||||
$status_id = $request->input('status_id');
|
||||
|
@ -310,7 +291,7 @@ class ComposeController extends Controller
|
|||
->whereProfileId($profile_id)
|
||||
->first();
|
||||
|
||||
if(!$tag) {
|
||||
if (! $tag) {
|
||||
return [];
|
||||
}
|
||||
Notification::whereItemType('App\MediaTag')
|
||||
|
@ -326,37 +307,38 @@ class ComposeController extends Controller
|
|||
|
||||
public function searchLocation(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
abort_if(! $request->user(), 403);
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|max:100'
|
||||
'q' => 'required|string|max:100',
|
||||
]);
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
$pid = $request->user()->profile_id;
|
||||
abort_if(!$pid, 400);
|
||||
abort_if(! $pid, 400);
|
||||
$q = e($request->input('q'));
|
||||
|
||||
$popular = Cache::remember('pf:search:location:v1:popular', 1209600, function() {
|
||||
$popular = Cache::remember('pf:search:location:v1:popular', 1209600, function () {
|
||||
$minId = SnowflakeService::byDate(now()->subDays(290));
|
||||
if(config('database.default') == 'pgsql') {
|
||||
if (config('database.default') == 'pgsql') {
|
||||
return Status::selectRaw('id, place_id, count(place_id) as pc')
|
||||
->whereNotNull('place_id')
|
||||
->where('id', '>', $minId)
|
||||
->orderByDesc('pc')
|
||||
->groupBy(['place_id', 'id'])
|
||||
->limit(400)
|
||||
->get()
|
||||
->filter(function($post) {
|
||||
return $post;
|
||||
})
|
||||
->map(function($place) {
|
||||
return [
|
||||
'id' => $place->place_id,
|
||||
'count' => $place->pc
|
||||
];
|
||||
})
|
||||
->unique('id')
|
||||
->values();
|
||||
->whereNotNull('place_id')
|
||||
->where('id', '>', $minId)
|
||||
->orderByDesc('pc')
|
||||
->groupBy(['place_id', 'id'])
|
||||
->limit(400)
|
||||
->get()
|
||||
->filter(function ($post) {
|
||||
return $post;
|
||||
})
|
||||
->map(function ($place) {
|
||||
return [
|
||||
'id' => $place->place_id,
|
||||
'count' => $place->pc,
|
||||
];
|
||||
})
|
||||
->unique('id')
|
||||
->values();
|
||||
}
|
||||
|
||||
return Status::selectRaw('id, place_id, count(place_id) as pc')
|
||||
->whereNotNull('place_id')
|
||||
->where('id', '>', $minId)
|
||||
|
@ -364,57 +346,58 @@ class ComposeController extends Controller
|
|||
->orderByDesc('pc')
|
||||
->limit(400)
|
||||
->get()
|
||||
->filter(function($post) {
|
||||
->filter(function ($post) {
|
||||
return $post;
|
||||
})
|
||||
->map(function($place) {
|
||||
->map(function ($place) {
|
||||
return [
|
||||
'id' => $place->place_id,
|
||||
'count' => $place->pc
|
||||
'count' => $place->pc,
|
||||
];
|
||||
});
|
||||
});
|
||||
$q = '%' . $q . '%';
|
||||
$q = '%'.$q.'%';
|
||||
$wildcard = config('database.default') === 'pgsql' ? 'ilike' : 'like';
|
||||
|
||||
$places = DB::table('places')
|
||||
->where('name', $wildcard, $q)
|
||||
->limit((strlen($q) > 5 ? 360 : 30))
|
||||
->get()
|
||||
->sortByDesc(function($place, $key) use($popular) {
|
||||
return $popular->filter(function($p) use($place) {
|
||||
return $p['id'] == $place->id;
|
||||
})->map(function($p) use($place) {
|
||||
return in_array($place->country, ['Canada', 'USA', 'France', 'Germany', 'United Kingdom']) ? $p['count'] : 1;
|
||||
})->values();
|
||||
})
|
||||
->map(function($r) {
|
||||
return [
|
||||
'id' => $r->id,
|
||||
'name' => $r->name,
|
||||
'country' => $r->country,
|
||||
'url' => url('/discover/places/' . $r->id . '/' . $r->slug)
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
->where('name', $wildcard, $q)
|
||||
->limit((strlen($q) > 5 ? 360 : 30))
|
||||
->get()
|
||||
->sortByDesc(function ($place, $key) use ($popular) {
|
||||
return $popular->filter(function ($p) use ($place) {
|
||||
return $p['id'] == $place->id;
|
||||
})->map(function ($p) use ($place) {
|
||||
return in_array($place->country, ['Canada', 'USA', 'France', 'Germany', 'United Kingdom']) ? $p['count'] : 1;
|
||||
})->values();
|
||||
})
|
||||
->map(function ($r) {
|
||||
return [
|
||||
'id' => $r->id,
|
||||
'name' => $r->name,
|
||||
'country' => $r->country,
|
||||
'url' => url('/discover/places/'.$r->id.'/'.$r->slug),
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return $places;
|
||||
}
|
||||
|
||||
public function searchMentionAutocomplete(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:2|max:50'
|
||||
'q' => 'required|string|min:2|max:50',
|
||||
]);
|
||||
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$q = $request->input('q');
|
||||
|
||||
if(Str::of($q)->startsWith('@')) {
|
||||
if(strlen($q) < 3) {
|
||||
if (Str::of($q)->startsWith('@')) {
|
||||
if (strlen($q) < 3) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -426,32 +409,33 @@ class ComposeController extends Controller
|
|||
|
||||
$blocked->push($request->user()->profile_id);
|
||||
|
||||
$results = Profile::select('id','domain','username')
|
||||
$results = Profile::select('id', 'domain', 'username')
|
||||
->whereNotIn('id', $blocked)
|
||||
->where('username','like','%'.$q.'%')
|
||||
->where('username', 'like', '%'.$q.'%')
|
||||
->groupBy('id', 'domain')
|
||||
->limit(15)
|
||||
->get()
|
||||
->map(function($profile) {
|
||||
->map(function ($profile) {
|
||||
$username = $profile->domain ? substr($profile->username, 1) : $profile->username;
|
||||
|
||||
return [
|
||||
'key' => '@' . str_limit($username, 30),
|
||||
'key' => '@'.str_limit($username, 30),
|
||||
'value' => $username,
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function searchHashtagAutocomplete(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:2|max:50'
|
||||
'q' => 'required|string|min:2|max:50',
|
||||
]);
|
||||
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$q = $request->input('q');
|
||||
|
||||
|
@ -461,12 +445,12 @@ class ComposeController extends Controller
|
|||
->whereIsBanned(false)
|
||||
->limit(5)
|
||||
->get()
|
||||
->map(function($tag) {
|
||||
->map(function ($tag) {
|
||||
return [
|
||||
'key' => '#' . $tag->slug,
|
||||
'value' => $tag->slug
|
||||
'key' => '#'.$tag->slug,
|
||||
'value' => $tag->slug,
|
||||
];
|
||||
});
|
||||
});
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
@ -474,8 +458,8 @@ class ComposeController extends Controller
|
|||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500),
|
||||
'media.*' => 'required',
|
||||
'caption' => 'nullable|string|max:'.config_cache('pixelfed.max_caption_length', 500),
|
||||
'media.*' => 'required',
|
||||
'media.*.id' => 'required|integer|min:1',
|
||||
'media.*.filter_class' => 'nullable|alpha_dash|max:30',
|
||||
'media.*.license' => 'nullable|string|max:140',
|
||||
|
@ -491,14 +475,14 @@ class ComposeController extends Controller
|
|||
// 'optimize_media' => 'nullable'
|
||||
]);
|
||||
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
if(config('costar.enabled') == true) {
|
||||
if (config('costar.enabled') == true) {
|
||||
$blockedKeywords = config('costar.keyword.block');
|
||||
if($blockedKeywords !== null && $request->caption) {
|
||||
if ($blockedKeywords !== null && $request->caption) {
|
||||
$keywords = config('costar.keyword.block');
|
||||
foreach($keywords as $kw) {
|
||||
if(Str::contains($request->caption, $kw) == true) {
|
||||
foreach ($keywords as $kw) {
|
||||
if (Str::contains($request->caption, $kw) == true) {
|
||||
abort(400, 'Invalid object');
|
||||
}
|
||||
}
|
||||
|
@ -508,9 +492,9 @@ class ComposeController extends Controller
|
|||
$user = $request->user();
|
||||
$profile = $user->profile;
|
||||
|
||||
$limitKey = 'compose:rate-limit:store:' . $user->id;
|
||||
$limitKey = 'compose:rate-limit:store:'.$user->id;
|
||||
$limitTtl = now()->addMinutes(15);
|
||||
$limitReached = Cache::remember($limitKey, $limitTtl, function() use($user) {
|
||||
$limitReached = Cache::remember($limitKey, $limitTtl, function () use ($user) {
|
||||
$dailyLimit = Status::whereProfileId($user->profile_id)
|
||||
->whereNull('in_reply_to_id')
|
||||
->whereNull('reblog_of_id')
|
||||
|
@ -534,12 +518,12 @@ class ComposeController extends Controller
|
|||
$tagged = $request->input('tagged');
|
||||
$optimize_media = (bool) $request->input('optimize_media');
|
||||
|
||||
foreach($medias as $k => $media) {
|
||||
if($k + 1 > config_cache('pixelfed.max_album_length')) {
|
||||
foreach ($medias as $k => $media) {
|
||||
if ($k + 1 > config_cache('pixelfed.max_album_length')) {
|
||||
continue;
|
||||
}
|
||||
$m = Media::findOrFail($media['id']);
|
||||
if($m->profile_id !== $profile->id || $m->status_id) {
|
||||
if ($m->profile_id !== $profile->id || $m->status_id) {
|
||||
abort(403, 'Invalid media id');
|
||||
}
|
||||
$m->filter_class = in_array($media['filter_class'], Filter::classes()) ? $media['filter_class'] : null;
|
||||
|
@ -547,7 +531,7 @@ class ComposeController extends Controller
|
|||
$m->caption = isset($media['alt']) ? strip_tags($media['alt']) : null;
|
||||
$m->order = isset($media['cursor']) && is_int($media['cursor']) ? (int) $media['cursor'] : $k;
|
||||
|
||||
if($cw == true || $profile->cw == true) {
|
||||
if ($cw == true || $profile->cw == true) {
|
||||
$m->is_nsfw = $cw;
|
||||
$status->is_nsfw = $cw;
|
||||
}
|
||||
|
@ -560,19 +544,19 @@ class ComposeController extends Controller
|
|||
|
||||
$mediaType = StatusController::mimeTypeCheck($mimes);
|
||||
|
||||
if(in_array($mediaType, ['photo', 'video', 'photo:album']) == false) {
|
||||
if (in_array($mediaType, ['photo', 'video', 'photo:album']) == false) {
|
||||
abort(400, __('exception.compose.invalid.album'));
|
||||
}
|
||||
|
||||
if($place && is_array($place)) {
|
||||
if ($place && is_array($place)) {
|
||||
$status->place_id = $place['id'];
|
||||
}
|
||||
|
||||
if($request->filled('comments_disabled')) {
|
||||
if ($request->filled('comments_disabled')) {
|
||||
$status->comments_disabled = (bool) $request->input('comments_disabled');
|
||||
}
|
||||
|
||||
if($request->filled('spoiler_text') && $cw) {
|
||||
if ($request->filled('spoiler_text') && $cw) {
|
||||
$status->cw_summary = $request->input('spoiler_text');
|
||||
}
|
||||
|
||||
|
@ -583,7 +567,7 @@ class ComposeController extends Controller
|
|||
$status->profile_id = $profile->id;
|
||||
$status->save();
|
||||
|
||||
foreach($attachments as $media) {
|
||||
foreach ($attachments as $media) {
|
||||
$media->status_id = $status->id;
|
||||
$media->save();
|
||||
}
|
||||
|
@ -597,7 +581,7 @@ class ComposeController extends Controller
|
|||
$status->type = $mediaType;
|
||||
$status->save();
|
||||
|
||||
foreach($tagged as $tg) {
|
||||
foreach ($tagged as $tg) {
|
||||
$mt = new MediaTag;
|
||||
$mt->status_id = $status->id;
|
||||
$mt->media_id = $status->media->first()->id;
|
||||
|
@ -612,17 +596,17 @@ class ComposeController extends Controller
|
|||
MediaTagService::sendNotification($mt);
|
||||
}
|
||||
|
||||
if($request->filled('collections')) {
|
||||
if ($request->filled('collections')) {
|
||||
$collections = Collection::whereProfileId($profile->id)
|
||||
->find($request->input('collections'))
|
||||
->each(function($collection) use($status) {
|
||||
->each(function ($collection) use ($status) {
|
||||
$count = $collection->items()->count();
|
||||
CollectionItem::firstOrCreate([
|
||||
'collection_id' => $collection->id,
|
||||
'object_type' => 'App\Status',
|
||||
'object_id' => $status->id
|
||||
'object_id' => $status->id,
|
||||
], [
|
||||
'order' => $count
|
||||
'order' => $count,
|
||||
]);
|
||||
|
||||
CollectionService::addItem(
|
||||
|
@ -643,7 +627,7 @@ class ComposeController extends Controller
|
|||
Cache::forget('profile:status_count:'.$profile->id);
|
||||
Cache::forget('status:transformer:media:attachments:'.$status->id);
|
||||
Cache::forget($user->storageUsedKey());
|
||||
Cache::forget('profile:embed:' . $status->profile_id);
|
||||
Cache::forget('profile:embed:'.$status->profile_id);
|
||||
Cache::forget($limitKey);
|
||||
|
||||
return $status->url();
|
||||
|
@ -653,7 +637,7 @@ class ComposeController extends Controller
|
|||
{
|
||||
abort_unless(config('exp.top'), 404);
|
||||
$this->validate($request, [
|
||||
'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500),
|
||||
'caption' => 'nullable|string|max:'.config_cache('pixelfed.max_caption_length', 500),
|
||||
'cw' => 'nullable|boolean',
|
||||
'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10',
|
||||
'place' => 'nullable',
|
||||
|
@ -661,14 +645,14 @@ class ComposeController extends Controller
|
|||
'tagged' => 'nullable',
|
||||
]);
|
||||
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
if(config('costar.enabled') == true) {
|
||||
if (config('costar.enabled') == true) {
|
||||
$blockedKeywords = config('costar.keyword.block');
|
||||
if($blockedKeywords !== null && $request->caption) {
|
||||
if ($blockedKeywords !== null && $request->caption) {
|
||||
$keywords = config('costar.keyword.block');
|
||||
foreach($keywords as $kw) {
|
||||
if(Str::contains($request->caption, $kw) == true) {
|
||||
foreach ($keywords as $kw) {
|
||||
if (Str::contains($request->caption, $kw) == true) {
|
||||
abort(400, 'Invalid object');
|
||||
}
|
||||
}
|
||||
|
@ -683,11 +667,11 @@ class ComposeController extends Controller
|
|||
$cw = $request->input('cw');
|
||||
$tagged = $request->input('tagged');
|
||||
|
||||
if($place && is_array($place)) {
|
||||
if ($place && is_array($place)) {
|
||||
$status->place_id = $place['id'];
|
||||
}
|
||||
|
||||
if($request->filled('comments_disabled')) {
|
||||
if ($request->filled('comments_disabled')) {
|
||||
$status->comments_disabled = (bool) $request->input('comments_disabled');
|
||||
}
|
||||
|
||||
|
@ -707,11 +691,11 @@ class ComposeController extends Controller
|
|||
'bg_id' => 1,
|
||||
'font_size' => strlen($status->caption) <= 140 ? 'h1' : 'h3',
|
||||
'length' => strlen($status->caption),
|
||||
]
|
||||
],
|
||||
], $entities), JSON_UNESCAPED_SLASHES);
|
||||
$status->save();
|
||||
|
||||
foreach($tagged as $tg) {
|
||||
foreach ($tagged as $tg) {
|
||||
$mt = new MediaTag;
|
||||
$mt->status_id = $status->id;
|
||||
$mt->media_id = $status->media->first()->id;
|
||||
|
@ -726,7 +710,6 @@ class ComposeController extends Controller
|
|||
MediaTagService::sendNotification($mt);
|
||||
}
|
||||
|
||||
|
||||
Cache::forget('user:account:id:'.$profile->user_id);
|
||||
Cache::forget('_api:statuses:recent_9:'.$profile->id);
|
||||
Cache::forget('profile:status_count:'.$profile->id);
|
||||
|
@ -737,18 +720,18 @@ class ComposeController extends Controller
|
|||
public function mediaProcessingCheck(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'id' => 'required|integer|min:1'
|
||||
'id' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$media = Media::whereUserId($request->user()->id)
|
||||
->whereNull('status_id')
|
||||
->findOrFail($request->input('id'));
|
||||
|
||||
if(config('pixelfed.media_fast_process')) {
|
||||
if (config('pixelfed.media_fast_process')) {
|
||||
return [
|
||||
'finished' => true
|
||||
'finished' => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -758,31 +741,31 @@ class ComposeController extends Controller
|
|||
case 'image/jpeg':
|
||||
case 'image/png':
|
||||
case 'video/mp4':
|
||||
$finished = config_cache('pixelfed.cloud_storage') ? (bool) $media->cdn_url : (bool) $media->processed_at;
|
||||
$finished = (bool) config_cache('pixelfed.cloud_storage') ? (bool) $media->cdn_url : (bool) $media->processed_at;
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
// code...
|
||||
break;
|
||||
}
|
||||
|
||||
return [
|
||||
'finished' => $finished
|
||||
'finished' => $finished,
|
||||
];
|
||||
}
|
||||
|
||||
public function composeSettings(Request $request)
|
||||
{
|
||||
$uid = $request->user()->id;
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$default = [
|
||||
'default_license' => 1,
|
||||
'media_descriptions' => false,
|
||||
'max_altext_length' => config_cache('pixelfed.max_altext_length')
|
||||
'max_altext_length' => config_cache('pixelfed.max_altext_length'),
|
||||
];
|
||||
$settings = AccountService::settings($uid);
|
||||
if(isset($settings['other']) && isset($settings['other']['scope'])) {
|
||||
if (isset($settings['other']) && isset($settings['other']['scope'])) {
|
||||
$s = $settings['compose_settings'];
|
||||
$s['default_scope'] = $settings['other']['scope'];
|
||||
$settings['compose_settings'] = $s;
|
||||
|
@ -794,23 +777,22 @@ class ComposeController extends Controller
|
|||
public function createPoll(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'caption' => 'nullable|string|max:'.config('pixelfed.max_caption_length', 500),
|
||||
'caption' => 'nullable|string|max:'.config_cache('pixelfed.max_caption_length', 500),
|
||||
'cw' => 'nullable|boolean',
|
||||
'visibility' => 'required|string|in:public,private',
|
||||
'comments_disabled' => 'nullable',
|
||||
'expiry' => 'required|in:60,360,1440,10080',
|
||||
'pollOptions' => 'required|array|min:1|max:4'
|
||||
'pollOptions' => 'required|array|min:1|max:4',
|
||||
]);
|
||||
abort(404);
|
||||
abort_if(config('instance.polls.enabled') == false, 404, 'Polls not enabled');
|
||||
abort_if($request->user()->has_roles && !UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($request->user()->has_roles && ! UserRoleService::can('can-post', $request->user()->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
abort_if(Status::whereType('poll')
|
||||
->whereProfileId($request->user()->profile_id)
|
||||
->whereCaption($request->input('caption'))
|
||||
->where('created_at', '>', now()->subDays(2))
|
||||
->exists()
|
||||
, 422, 'Duplicate detected.');
|
||||
->exists(), 422, 'Duplicate detected.');
|
||||
|
||||
$status = new Status;
|
||||
$status->profile_id = $request->user()->profile_id;
|
||||
|
@ -827,7 +809,7 @@ class ComposeController extends Controller
|
|||
$poll->profile_id = $status->profile_id;
|
||||
$poll->poll_options = $request->input('pollOptions');
|
||||
$poll->expires_at = now()->addMinutes($request->input('expiry'));
|
||||
$poll->cached_tallies = collect($poll->poll_options)->map(function($o) {
|
||||
$poll->cached_tallies = collect($poll->poll_options)->map(function ($o) {
|
||||
return 0;
|
||||
})->toArray();
|
||||
$poll->save();
|
||||
|
|
|
@ -0,0 +1,399 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\User;
|
||||
use App\Models\CuratedRegister;
|
||||
use App\Models\CuratedRegisterActivity;
|
||||
use App\Services\EmailService;
|
||||
use App\Services\BouncerService;
|
||||
use App\Util\Lexer\RestrictedNames;
|
||||
use App\Mail\CuratedRegisterConfirmEmail;
|
||||
use App\Mail\CuratedRegisterNotifyAdmin;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Jobs\CuratedOnboarding\CuratedOnboardingNotifyAdminNewApplicationPipeline;
|
||||
|
||||
class CuratedRegisterController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
abort_unless((bool) config_cache('instance.curated_registration.enabled'), 404);
|
||||
|
||||
if((bool) config_cache('pixelfed.open_registration')) {
|
||||
abort_if(config('instance.curated_registration.state.only_enabled_on_closed_reg'), 404);
|
||||
} else {
|
||||
abort_unless(config('instance.curated_registration.state.fallback_on_closed_reg'), 404);
|
||||
}
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
abort_if($request->user(), 404);
|
||||
return view('auth.curated-register.index', ['step' => 1]);
|
||||
}
|
||||
|
||||
public function concierge(Request $request)
|
||||
{
|
||||
abort_if($request->user(), 404);
|
||||
$emailConfirmed = $request->session()->has('cur-reg-con.email-confirmed') &&
|
||||
$request->has('next') &&
|
||||
$request->session()->has('cur-reg-con.cr-id');
|
||||
return view('auth.curated-register.concierge', compact('emailConfirmed'));
|
||||
}
|
||||
|
||||
public function conciergeResponseSent(Request $request)
|
||||
{
|
||||
return view('auth.curated-register.user_response_sent');
|
||||
}
|
||||
|
||||
public function conciergeFormShow(Request $request)
|
||||
{
|
||||
abort_if($request->user(), 404);
|
||||
abort_unless(
|
||||
$request->session()->has('cur-reg-con.email-confirmed') &&
|
||||
$request->session()->has('cur-reg-con.cr-id') &&
|
||||
$request->session()->has('cur-reg-con.ac-id'), 404);
|
||||
$crid = $request->session()->get('cur-reg-con.cr-id');
|
||||
$arid = $request->session()->get('cur-reg-con.ac-id');
|
||||
$showCaptcha = config('instance.curated_registration.captcha_enabled');
|
||||
if($attempts = $request->session()->get('cur-reg-con-attempt')) {
|
||||
$showCaptcha = $attempts && $attempts >= 2;
|
||||
} else {
|
||||
$showCaptcha = false;
|
||||
}
|
||||
$activity = CuratedRegisterActivity::whereRegisterId($crid)->whereFromAdmin(true)->findOrFail($arid);
|
||||
return view('auth.curated-register.concierge_form', compact('activity', 'showCaptcha'));
|
||||
}
|
||||
|
||||
public function conciergeFormStore(Request $request)
|
||||
{
|
||||
abort_if($request->user(), 404);
|
||||
$request->session()->increment('cur-reg-con-attempt');
|
||||
abort_unless(
|
||||
$request->session()->has('cur-reg-con.email-confirmed') &&
|
||||
$request->session()->has('cur-reg-con.cr-id') &&
|
||||
$request->session()->has('cur-reg-con.ac-id'), 404);
|
||||
$attempts = $request->session()->get('cur-reg-con-attempt');
|
||||
$messages = [];
|
||||
$rules = [
|
||||
'response' => 'required|string|min:5|max:1000',
|
||||
'crid' => 'required|integer|min:1',
|
||||
'acid' => 'required|integer|min:1'
|
||||
];
|
||||
if(config('instance.curated_registration.captcha_enabled') && $attempts >= 3) {
|
||||
$rules['h-captcha-response'] = 'required|captcha';
|
||||
$messages['h-captcha-response.required'] = 'The captcha must be filled';
|
||||
}
|
||||
$this->validate($request, $rules, $messages);
|
||||
$crid = $request->session()->get('cur-reg-con.cr-id');
|
||||
$acid = $request->session()->get('cur-reg-con.ac-id');
|
||||
abort_if((string) $crid !== $request->input('crid'), 404);
|
||||
abort_if((string) $acid !== $request->input('acid'), 404);
|
||||
|
||||
if(CuratedRegisterActivity::whereRegisterId($crid)->whereReplyToId($acid)->exists()) {
|
||||
return redirect()->back()->withErrors(['code' => 'You already replied to this request.']);
|
||||
}
|
||||
|
||||
$act = CuratedRegisterActivity::create([
|
||||
'register_id' => $crid,
|
||||
'reply_to_id' => $acid,
|
||||
'type' => 'user_response',
|
||||
'message' => $request->input('response'),
|
||||
'from_user' => true,
|
||||
'action_required' => true,
|
||||
]);
|
||||
|
||||
CuratedRegister::findOrFail($crid)->update(['user_has_responded' => true]);
|
||||
$request->session()->pull('cur-reg-con');
|
||||
$request->session()->pull('cur-reg-con-attempt');
|
||||
|
||||
return view('auth.curated-register.user_response_sent');
|
||||
}
|
||||
|
||||
public function conciergeStore(Request $request)
|
||||
{
|
||||
abort_if($request->user(), 404);
|
||||
$rules = [
|
||||
'sid' => 'required_if:action,email|integer|min:1|max:20000000',
|
||||
'id' => 'required_if:action,email|integer|min:1|max:20000000',
|
||||
'code' => 'required_if:action,email',
|
||||
'action' => 'required|string|in:email,message',
|
||||
'email' => 'required_if:action,email|email',
|
||||
'response' => 'required_if:action,message|string|min:20|max:1000',
|
||||
];
|
||||
$messages = [];
|
||||
if(config('instance.curated_registration.captcha_enabled')) {
|
||||
$rules['h-captcha-response'] = 'required|captcha';
|
||||
$messages['h-captcha-response.required'] = 'The captcha must be filled';
|
||||
}
|
||||
$this->validate($request, $rules, $messages);
|
||||
|
||||
$action = $request->input('action');
|
||||
$sid = $request->input('sid');
|
||||
$id = $request->input('id');
|
||||
$code = $request->input('code');
|
||||
$email = $request->input('email');
|
||||
|
||||
$cr = CuratedRegister::whereIsClosed(false)->findOrFail($sid);
|
||||
$ac = CuratedRegisterActivity::whereRegisterId($cr->id)->whereFromAdmin(true)->findOrFail($id);
|
||||
|
||||
if(!hash_equals($ac->secret_code, $code)) {
|
||||
return redirect()->back()->withErrors(['code' => 'Invalid code']);
|
||||
}
|
||||
|
||||
if(!hash_equals($cr->email, $email)) {
|
||||
return redirect()->back()->withErrors(['email' => 'Invalid email']);
|
||||
}
|
||||
|
||||
$request->session()->put('cur-reg-con.email-confirmed', true);
|
||||
$request->session()->put('cur-reg-con.cr-id', $cr->id);
|
||||
$request->session()->put('cur-reg-con.ac-id', $ac->id);
|
||||
$emailConfirmed = true;
|
||||
return redirect('/auth/sign_up/concierge/form');
|
||||
}
|
||||
|
||||
public function confirmEmail(Request $request)
|
||||
{
|
||||
if($request->user()) {
|
||||
return redirect(route('help.email-confirmation-issues'));
|
||||
}
|
||||
return view('auth.curated-register.confirm_email');
|
||||
}
|
||||
|
||||
public function emailConfirmed(Request $request)
|
||||
{
|
||||
if($request->user()) {
|
||||
return redirect(route('help.email-confirmation-issues'));
|
||||
}
|
||||
return view('auth.curated-register.email_confirmed');
|
||||
}
|
||||
|
||||
public function resendConfirmation(Request $request)
|
||||
{
|
||||
return view('auth.curated-register.resend-confirmation');
|
||||
}
|
||||
|
||||
public function resendConfirmationProcess(Request $request)
|
||||
{
|
||||
$rules = [
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
app()->environment() === 'production' ? 'email:rfc,dns,spoof' : 'email',
|
||||
'exists:curated_registers',
|
||||
]
|
||||
];
|
||||
|
||||
$messages = [];
|
||||
|
||||
if(config('instance.curated_registration.captcha_enabled')) {
|
||||
$rules['h-captcha-response'] = 'required|captcha';
|
||||
$messages['h-captcha-response.required'] = 'The captcha must be filled';
|
||||
}
|
||||
|
||||
$this->validate($request, $rules, $messages);
|
||||
|
||||
$cur = CuratedRegister::whereEmail($request->input('email'))->whereIsClosed(false)->first();
|
||||
if(!$cur) {
|
||||
return redirect()->back()->withErrors(['email' => 'The selected email is invalid.']);
|
||||
}
|
||||
|
||||
$totalCount = CuratedRegisterActivity::whereRegisterId($cur->id)
|
||||
->whereType('user_resend_email_confirmation')
|
||||
->count();
|
||||
|
||||
if($totalCount && $totalCount >= config('instance.curated_registration.resend_confirmation_limit')) {
|
||||
return redirect()->back()->withErrors(['email' => 'You have re-attempted too many times. To proceed with your application, please <a href="/site/contact" class="text-white" style="text-decoration: underline;">contact the admin team</a>.']);
|
||||
}
|
||||
|
||||
$count = CuratedRegisterActivity::whereRegisterId($cur->id)
|
||||
->whereType('user_resend_email_confirmation')
|
||||
->where('created_at', '>', now()->subHours(12))
|
||||
->count();
|
||||
|
||||
if($count) {
|
||||
return redirect()->back()->withErrors(['email' => 'You can only re-send the confirmation email once per 12 hours. Try again later.']);
|
||||
}
|
||||
|
||||
CuratedRegisterActivity::create([
|
||||
'register_id' => $cur->id,
|
||||
'type' => 'user_resend_email_confirmation',
|
||||
'admin_only_view' => true,
|
||||
'from_admin' => false,
|
||||
'from_user' => false,
|
||||
'action_required' => false,
|
||||
]);
|
||||
|
||||
Mail::to($cur->email)->send(new CuratedRegisterConfirmEmail($cur));
|
||||
return view('auth.curated-register.resent-confirmation');
|
||||
return $request->all();
|
||||
}
|
||||
|
||||
public function confirmEmailHandle(Request $request)
|
||||
{
|
||||
$rules = [
|
||||
'sid' => 'required',
|
||||
'code' => 'required'
|
||||
];
|
||||
$messages = [];
|
||||
if(config('instance.curated_registration.captcha_enabled')) {
|
||||
$rules['h-captcha-response'] = 'required|captcha';
|
||||
$messages['h-captcha-response.required'] = 'The captcha must be filled';
|
||||
}
|
||||
$this->validate($request, $rules, $messages);
|
||||
|
||||
$cr = CuratedRegister::whereNull('email_verified_at')
|
||||
->where('created_at', '>', now()->subHours(24))
|
||||
->find($request->input('sid'));
|
||||
if(!$cr) {
|
||||
return redirect(route('help.email-confirmation-issues'));
|
||||
}
|
||||
if(!hash_equals($cr->verify_code, $request->input('code'))) {
|
||||
return redirect(route('help.email-confirmation-issues'));
|
||||
}
|
||||
$cr->email_verified_at = now();
|
||||
$cr->save();
|
||||
|
||||
if(config('instance.curated_registration.notify.admin.on_verify_email.enabled')) {
|
||||
CuratedOnboardingNotifyAdminNewApplicationPipeline::dispatch($cr);
|
||||
}
|
||||
return view('auth.curated-register.email_confirmed');
|
||||
}
|
||||
|
||||
public function proceed(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'step' => 'required|integer|in:1,2,3,4'
|
||||
]);
|
||||
$step = $request->input('step');
|
||||
|
||||
switch($step) {
|
||||
case 1:
|
||||
$step = 2;
|
||||
$request->session()->put('cur-step', 1);
|
||||
return view('auth.curated-register.index', compact('step'));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
$this->stepTwo($request);
|
||||
$step = 3;
|
||||
$request->session()->put('cur-step', 2);
|
||||
return view('auth.curated-register.index', compact('step'));
|
||||
break;
|
||||
|
||||
case 3:
|
||||
$this->stepThree($request);
|
||||
$step = 3;
|
||||
$request->session()->put('cur-step', 3);
|
||||
$verifiedEmail = true;
|
||||
$request->session()->pull('cur-reg');
|
||||
return view('auth.curated-register.index', compact('step', 'verifiedEmail'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function stepTwo($request)
|
||||
{
|
||||
if($request->filled('reason')) {
|
||||
$request->session()->put('cur-reg.form-reason', $request->input('reason'));
|
||||
}
|
||||
if($request->filled('username')) {
|
||||
$request->session()->put('cur-reg.form-username', $request->input('username'));
|
||||
}
|
||||
if($request->filled('email')) {
|
||||
$request->session()->put('cur-reg.form-email', $request->input('email'));
|
||||
}
|
||||
$this->validate($request, [
|
||||
'username' => [
|
||||
'required',
|
||||
'min:2',
|
||||
'max:15',
|
||||
'unique:curated_registers',
|
||||
'unique:users',
|
||||
function ($attribute, $value, $fail) {
|
||||
$dash = substr_count($value, '-');
|
||||
$underscore = substr_count($value, '_');
|
||||
$period = substr_count($value, '.');
|
||||
|
||||
if(ends_with($value, ['.php', '.js', '.css'])) {
|
||||
return $fail('Username is invalid.');
|
||||
}
|
||||
|
||||
if(($dash + $underscore + $period) > 1) {
|
||||
return $fail('Username is invalid. Can only contain one dash (-), period (.) or underscore (_).');
|
||||
}
|
||||
|
||||
if (!ctype_alnum($value[0])) {
|
||||
return $fail('Username is invalid. Must start with a letter or number.');
|
||||
}
|
||||
|
||||
if (!ctype_alnum($value[strlen($value) - 1])) {
|
||||
return $fail('Username is invalid. Must end with a letter or number.');
|
||||
}
|
||||
|
||||
$val = str_replace(['_', '.', '-'], '', $value);
|
||||
if(!ctype_alnum($val)) {
|
||||
return $fail('Username is invalid. Username must be alpha-numeric and may contain dashes (-), periods (.) and underscores (_).');
|
||||
}
|
||||
|
||||
$restricted = RestrictedNames::get();
|
||||
if (in_array(strtolower($value), array_map('strtolower', $restricted))) {
|
||||
return $fail('Username cannot be used.');
|
||||
}
|
||||
},
|
||||
],
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
app()->environment() === 'production' ? 'email:rfc,dns,spoof' : 'email',
|
||||
'max:255',
|
||||
'unique:users',
|
||||
'unique:curated_registers',
|
||||
function ($attribute, $value, $fail) {
|
||||
$banned = EmailService::isBanned($value);
|
||||
if($banned) {
|
||||
return $fail('Email is invalid.');
|
||||
}
|
||||
},
|
||||
],
|
||||
'password' => 'required|min:8',
|
||||
'password_confirmation' => 'required|same:password',
|
||||
'reason' => 'required|min:20|max:1000',
|
||||
'agree' => 'required|accepted'
|
||||
]);
|
||||
$request->session()->put('cur-reg.form-email', $request->input('email'));
|
||||
$request->session()->put('cur-reg.form-password', $request->input('password'));
|
||||
}
|
||||
|
||||
protected function stepThree($request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'email' => [
|
||||
'required',
|
||||
'string',
|
||||
app()->environment() === 'production' ? 'email:rfc,dns,spoof' : 'email',
|
||||
'max:255',
|
||||
'unique:users',
|
||||
'unique:curated_registers',
|
||||
function ($attribute, $value, $fail) {
|
||||
$banned = EmailService::isBanned($value);
|
||||
if($banned) {
|
||||
return $fail('Email is invalid.');
|
||||
}
|
||||
},
|
||||
]
|
||||
]);
|
||||
$cr = new CuratedRegister;
|
||||
$cr->email = $request->email;
|
||||
$cr->username = $request->session()->get('cur-reg.form-username');
|
||||
$cr->password = bcrypt($request->session()->get('cur-reg.form-password'));
|
||||
$cr->ip_address = $request->ip();
|
||||
$cr->reason_to_join = $request->session()->get('cur-reg.form-reason');
|
||||
$cr->verify_code = Str::random(40);
|
||||
$cr->save();
|
||||
|
||||
Mail::to($cr->email)->send(new CuratedRegisterConfirmEmail($cr));
|
||||
}
|
||||
}
|
|
@ -309,6 +309,7 @@ class DirectMessageController extends Controller
|
|||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-direct-message', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->created_at->gt(now()->subHours(72)), 400, 'You need to wait a bit before you can DM another account');
|
||||
$profile = $user->profile;
|
||||
$recipient = Profile::where('id', '!=', $profile->id)->findOrFail($request->input('to_id'));
|
||||
|
||||
|
|
|
@ -2,366 +2,422 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\{
|
||||
DiscoverCategory,
|
||||
Follower,
|
||||
Hashtag,
|
||||
HashtagFollow,
|
||||
Instance,
|
||||
Like,
|
||||
Profile,
|
||||
Status,
|
||||
StatusHashtag,
|
||||
UserFilter
|
||||
};
|
||||
use Auth, DB, Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Hashtag;
|
||||
use App\Instance;
|
||||
use App\Like;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\AdminShadowFilterService;
|
||||
use App\Services\BookmarkService;
|
||||
use App\Services\ConfigCacheService;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\HashtagService;
|
||||
use App\Services\LikeService;
|
||||
use App\Services\ReblogService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\SnowflakeService;
|
||||
use App\Services\StatusHashtagService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\TrendingHashtagService;
|
||||
use App\Services\UserFilterService;
|
||||
use App\Status;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DiscoverController extends Controller
|
||||
{
|
||||
public function home(Request $request)
|
||||
{
|
||||
abort_if(!Auth::check() && config('instance.discover.public') == false, 403);
|
||||
return view('discover.home');
|
||||
}
|
||||
public function home(Request $request)
|
||||
{
|
||||
abort_if(! Auth::check() && config('instance.discover.public') == false, 403);
|
||||
|
||||
public function showTags(Request $request, $hashtag)
|
||||
{
|
||||
abort_if(!config('instance.discover.tags.is_public') && !Auth::check(), 403);
|
||||
return view('discover.home');
|
||||
}
|
||||
|
||||
$tag = Hashtag::whereName($hashtag)
|
||||
->orWhere('slug', $hashtag)
|
||||
->where('is_banned', '!=', true)
|
||||
->firstOrFail();
|
||||
$tagCount = StatusHashtagService::count($tag->id);
|
||||
return view('discover.tags.show', compact('tag', 'tagCount'));
|
||||
}
|
||||
public function showTags(Request $request, $hashtag)
|
||||
{
|
||||
if ($request->user()) {
|
||||
return redirect('/i/web/hashtag/'.$hashtag.'?src=pd');
|
||||
}
|
||||
abort_if(! config('instance.discover.tags.is_public') && ! Auth::check(), 403);
|
||||
|
||||
public function getHashtags(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
abort_if(!config('instance.discover.tags.is_public') && !$user, 403);
|
||||
$tag = Hashtag::whereName($hashtag)
|
||||
->orWhere('slug', $hashtag)
|
||||
->where('is_banned', '!=', true)
|
||||
->firstOrFail();
|
||||
$tagCount = $tag->cached_count ?? 0;
|
||||
|
||||
$this->validate($request, [
|
||||
'hashtag' => 'required|string|min:1|max:124',
|
||||
'page' => 'nullable|integer|min:1|max:' . ($user ? 29 : 3)
|
||||
]);
|
||||
return view('discover.tags.show', compact('tag', 'tagCount'));
|
||||
}
|
||||
|
||||
$page = $request->input('page') ?? '1';
|
||||
$end = $page > 1 ? $page * 9 : 0;
|
||||
$tag = $request->input('hashtag');
|
||||
public function getHashtags(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
abort_if(! config('instance.discover.tags.is_public') && ! $user, 403);
|
||||
|
||||
if(config('database.default') === 'pgsql') {
|
||||
$hashtag = Hashtag::where('name', 'ilike', $tag)->firstOrFail();
|
||||
} else {
|
||||
$hashtag = Hashtag::whereName($tag)->firstOrFail();
|
||||
}
|
||||
$this->validate($request, [
|
||||
'hashtag' => 'required|string|min:1|max:124',
|
||||
'page' => 'nullable|integer|min:1|max:'.($user ? 29 : 3),
|
||||
]);
|
||||
|
||||
if($hashtag->is_banned == true) {
|
||||
return [];
|
||||
}
|
||||
if($user) {
|
||||
$res['follows'] = HashtagService::isFollowing($user->profile_id, $hashtag->id);
|
||||
}
|
||||
$res['hashtag'] = [
|
||||
'name' => $hashtag->name,
|
||||
'url' => $hashtag->url()
|
||||
];
|
||||
if($user) {
|
||||
$tags = StatusHashtagService::get($hashtag->id, $page, $end);
|
||||
$res['tags'] = collect($tags)
|
||||
->map(function($tag) use($user) {
|
||||
$tag['status']['favourited'] = (bool) LikeService::liked($user->profile_id, $tag['status']['id']);
|
||||
$tag['status']['reblogged'] = (bool) ReblogService::get($user->profile_id, $tag['status']['id']);
|
||||
$tag['status']['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $tag['status']['id']);
|
||||
return $tag;
|
||||
})
|
||||
->filter(function($tag) {
|
||||
if(!StatusService::get($tag['status']['id'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
->values();
|
||||
} else {
|
||||
if($page != 1) {
|
||||
$res['tags'] = [];
|
||||
return $res;
|
||||
}
|
||||
$key = 'discover:tags:public_feed:' . $hashtag->id . ':page:' . $page;
|
||||
$tags = Cache::remember($key, 43200, function() use($hashtag, $page, $end) {
|
||||
return collect(StatusHashtagService::get($hashtag->id, $page, $end))
|
||||
->filter(function($tag) {
|
||||
if(!$tag['status']['local']) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
->values();
|
||||
});
|
||||
$res['tags'] = collect($tags)
|
||||
->filter(function($tag) {
|
||||
if(!StatusService::get($tag['status']['id'])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
->values();
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
$page = $request->input('page') ?? '1';
|
||||
$end = $page > 1 ? $page * 9 : 0;
|
||||
$tag = $request->input('hashtag');
|
||||
|
||||
public function profilesDirectory(Request $request)
|
||||
{
|
||||
return redirect('/')->with('statusRedirect', 'The Profile Directory is unavailable at this time.');
|
||||
}
|
||||
if (config('database.default') === 'pgsql') {
|
||||
$hashtag = Hashtag::where('name', 'ilike', $tag)->firstOrFail();
|
||||
} else {
|
||||
$hashtag = Hashtag::whereName($tag)->firstOrFail();
|
||||
}
|
||||
|
||||
public function profilesDirectoryApi(Request $request)
|
||||
{
|
||||
return ['error' => 'Temporarily unavailable.'];
|
||||
}
|
||||
if ($hashtag->is_banned == true) {
|
||||
return [];
|
||||
}
|
||||
if ($user) {
|
||||
$res['follows'] = HashtagService::isFollowing($user->profile_id, $hashtag->id);
|
||||
}
|
||||
$res['hashtag'] = [
|
||||
'name' => $hashtag->name,
|
||||
'url' => $hashtag->url(),
|
||||
];
|
||||
if ($user) {
|
||||
$tags = StatusHashtagService::get($hashtag->id, $page, $end);
|
||||
$res['tags'] = collect($tags)
|
||||
->map(function ($tag) use ($user) {
|
||||
$tag['status']['favourited'] = (bool) LikeService::liked($user->profile_id, $tag['status']['id']);
|
||||
$tag['status']['reblogged'] = (bool) ReblogService::get($user->profile_id, $tag['status']['id']);
|
||||
$tag['status']['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $tag['status']['id']);
|
||||
|
||||
public function trendingApi(Request $request)
|
||||
{
|
||||
abort_if(config('instance.discover.public') == false && !$request->user(), 403);
|
||||
return $tag;
|
||||
})
|
||||
->filter(function ($tag) {
|
||||
if (! StatusService::get($tag['status']['id'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->validate($request, [
|
||||
'range' => 'nullable|string|in:daily,monthly,yearly',
|
||||
]);
|
||||
return true;
|
||||
})
|
||||
->values();
|
||||
} else {
|
||||
if ($page != 1) {
|
||||
$res['tags'] = [];
|
||||
|
||||
$range = $request->input('range');
|
||||
$days = $range == 'monthly' ? 31 : ($range == 'daily' ? 1 : 365);
|
||||
$ttls = [
|
||||
1 => 1500,
|
||||
31 => 14400,
|
||||
365 => 86400
|
||||
];
|
||||
$key = ':api:discover:trending:v2.12:range:' . $days;
|
||||
return $res;
|
||||
}
|
||||
$key = 'discover:tags:public_feed:'.$hashtag->id.':page:'.$page;
|
||||
$tags = Cache::remember($key, 43200, function () use ($hashtag, $page, $end) {
|
||||
return collect(StatusHashtagService::get($hashtag->id, $page, $end))
|
||||
->filter(function ($tag) {
|
||||
if (! $tag['status']['local']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ids = Cache::remember($key, $ttls[$days], function() use($days) {
|
||||
$min_id = SnowflakeService::byDate(now()->subDays($days));
|
||||
return DB::table('statuses')
|
||||
->select(
|
||||
'id',
|
||||
'scope',
|
||||
'type',
|
||||
'is_nsfw',
|
||||
'likes_count',
|
||||
'created_at'
|
||||
)
|
||||
->where('id', '>', $min_id)
|
||||
->whereNull('uri')
|
||||
->whereScope('public')
|
||||
->whereIn('type', [
|
||||
'photo',
|
||||
'photo:album',
|
||||
'video'
|
||||
])
|
||||
->whereIsNsfw(false)
|
||||
->orderBy('likes_count','desc')
|
||||
->take(30)
|
||||
->pluck('id');
|
||||
});
|
||||
return true;
|
||||
})
|
||||
->values();
|
||||
});
|
||||
$res['tags'] = collect($tags)
|
||||
->filter(function ($tag) {
|
||||
if (! StatusService::get($tag['status']['id'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
|
||||
return true;
|
||||
})
|
||||
->values();
|
||||
}
|
||||
|
||||
$res = $ids->map(function($s) {
|
||||
return StatusService::get($s);
|
||||
})->filter(function($s) use($filtered) {
|
||||
return
|
||||
$s &&
|
||||
!in_array($s['account']['id'], $filtered) &&
|
||||
isset($s['account']);
|
||||
})->values();
|
||||
return $res;
|
||||
}
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
public function profilesDirectory(Request $request)
|
||||
{
|
||||
return redirect('/')->with('statusRedirect', 'The Profile Directory is unavailable at this time.');
|
||||
}
|
||||
|
||||
public function trendingHashtags(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
public function profilesDirectoryApi(Request $request)
|
||||
{
|
||||
return ['error' => 'Temporarily unavailable.'];
|
||||
}
|
||||
|
||||
$res = TrendingHashtagService::getTrending();
|
||||
return $res;
|
||||
}
|
||||
public function trendingApi(Request $request)
|
||||
{
|
||||
abort_if(config('instance.discover.public') == false && ! $request->user(), 403);
|
||||
|
||||
public function trendingPlaces(Request $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
$this->validate($request, [
|
||||
'range' => 'nullable|string|in:daily,monthly,yearly',
|
||||
]);
|
||||
|
||||
public function myMemories(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
abort_if(!$this->config()['memories']['enabled'], 404);
|
||||
$type = $request->input('type') ?? 'posts';
|
||||
$range = $request->input('range');
|
||||
$days = $range == 'monthly' ? 31 : ($range == 'daily' ? 1 : 365);
|
||||
$ttls = [
|
||||
1 => 1500,
|
||||
31 => 14400,
|
||||
365 => 86400,
|
||||
];
|
||||
$key = ':api:discover:trending:v2.12:range:'.$days;
|
||||
|
||||
switch($type) {
|
||||
case 'posts':
|
||||
$res = Status::whereProfileId($pid)
|
||||
->whereDay('created_at', date('d'))
|
||||
->whereMonth('created_at', date('m'))
|
||||
->whereYear('created_at', '!=', date('Y'))
|
||||
->whereNull(['reblog_of_id', 'in_reply_to_id'])
|
||||
->limit(20)
|
||||
->pluck('id')
|
||||
->map(function($id) {
|
||||
return StatusService::get($id, false);
|
||||
})
|
||||
->filter(function($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
break;
|
||||
$ids = Cache::remember($key, $ttls[$days], function () use ($days) {
|
||||
$min_id = SnowflakeService::byDate(now()->subDays($days));
|
||||
|
||||
case 'liked':
|
||||
$res = Like::whereProfileId($pid)
|
||||
->whereDay('created_at', date('d'))
|
||||
->whereMonth('created_at', date('m'))
|
||||
->whereYear('created_at', '!=', date('Y'))
|
||||
->orderByDesc('status_id')
|
||||
->limit(20)
|
||||
->pluck('status_id')
|
||||
->map(function($id) {
|
||||
$status = StatusService::get($id, false);
|
||||
$status['favourited'] = true;
|
||||
return $status;
|
||||
})
|
||||
->filter(function($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
break;
|
||||
}
|
||||
return DB::table('statuses')
|
||||
->select(
|
||||
'id',
|
||||
'scope',
|
||||
'type',
|
||||
'is_nsfw',
|
||||
'likes_count',
|
||||
'created_at'
|
||||
)
|
||||
->where('id', '>', $min_id)
|
||||
->whereNull('uri')
|
||||
->whereScope('public')
|
||||
->whereIn('type', [
|
||||
'photo',
|
||||
'photo:album',
|
||||
'video',
|
||||
])
|
||||
->whereIsNsfw(false)
|
||||
->orderBy('likes_count', 'desc')
|
||||
->take(30)
|
||||
->pluck('id');
|
||||
});
|
||||
|
||||
return $res;
|
||||
}
|
||||
$filtered = Auth::check() ? UserFilterService::filters(Auth::user()->profile_id) : [];
|
||||
|
||||
public function accountInsightsPopularPosts(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
abort_if(!$this->config()['insights']['enabled'], 404);
|
||||
$posts = Cache::remember('pf:discover:metro2:accinsights:popular:' . $pid, 43200, function() use ($pid) {
|
||||
return Status::whereProfileId($pid)
|
||||
->whereNotNull('likes_count')
|
||||
->orderByDesc('likes_count')
|
||||
->limit(12)
|
||||
->pluck('id')
|
||||
->map(function($id) {
|
||||
return StatusService::get($id, false);
|
||||
})
|
||||
->filter(function($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
});
|
||||
$res = $ids->map(function ($s) {
|
||||
return StatusService::get($s);
|
||||
})->filter(function ($s) use ($filtered) {
|
||||
return
|
||||
$s &&
|
||||
! in_array($s['account']['id'], $filtered) &&
|
||||
isset($s['account']);
|
||||
})->values();
|
||||
|
||||
return $posts;
|
||||
}
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
public function config()
|
||||
{
|
||||
$cc = ConfigCacheService::get('config.discover.features');
|
||||
if($cc) {
|
||||
return is_string($cc) ? json_decode($cc, true) : $cc;
|
||||
}
|
||||
return [
|
||||
'hashtags' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'memories' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'insights' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'friends' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'server' => [
|
||||
'enabled' => false,
|
||||
'mode' => 'allowlist',
|
||||
'domains' => []
|
||||
]
|
||||
];
|
||||
}
|
||||
public function trendingHashtags(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
public function serverTimeline(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 404);
|
||||
abort_if(!$this->config()['server']['enabled'], 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
$domain = $request->input('domain');
|
||||
$config = $this->config();
|
||||
$domains = explode(',', $config['server']['domains']);
|
||||
abort_unless(in_array($domain, $domains), 400);
|
||||
$res = TrendingHashtagService::getTrending();
|
||||
|
||||
$res = Status::whereNotNull('uri')
|
||||
->where('uri', 'like', 'https://' . $domain . '%')
|
||||
->whereNull(['in_reply_to_id', 'reblog_of_id'])
|
||||
->orderByDesc('id')
|
||||
->limit(12)
|
||||
->pluck('id')
|
||||
->map(function($id) {
|
||||
return StatusService::get($id);
|
||||
})
|
||||
->filter(function($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
return $res;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function enabledFeatures(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 404);
|
||||
return $this->config();
|
||||
}
|
||||
public function trendingPlaces(Request $request)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function updateFeatures(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 404);
|
||||
abort_if(!$request->user()->is_admin, 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
$this->validate($request, [
|
||||
'features.friends.enabled' => 'boolean',
|
||||
'features.hashtags.enabled' => 'boolean',
|
||||
'features.insights.enabled' => 'boolean',
|
||||
'features.memories.enabled' => 'boolean',
|
||||
'features.server.enabled' => 'boolean',
|
||||
]);
|
||||
$res = $request->input('features');
|
||||
if($res['server'] && isset($res['server']['domains']) && !empty($res['server']['domains'])) {
|
||||
$parts = explode(',', $res['server']['domains']);
|
||||
$parts = array_filter($parts, function($v) {
|
||||
$len = strlen($v);
|
||||
$pos = strpos($v, '.');
|
||||
$domain = trim($v);
|
||||
if($pos == false || $pos == ($len + 1)) {
|
||||
return false;
|
||||
}
|
||||
if(!Instance::whereDomain($domain)->exists()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
$parts = array_slice($parts, 0, 10);
|
||||
$d = implode(',', array_map('trim', $parts));
|
||||
$res['server']['domains'] = $d;
|
||||
}
|
||||
ConfigCacheService::put('config.discover.features', json_encode($res));
|
||||
return $res;
|
||||
}
|
||||
public function myMemories(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
abort_if(! $this->config()['memories']['enabled'], 404);
|
||||
$type = $request->input('type') ?? 'posts';
|
||||
|
||||
switch ($type) {
|
||||
case 'posts':
|
||||
$res = Status::whereProfileId($pid)
|
||||
->whereDay('created_at', date('d'))
|
||||
->whereMonth('created_at', date('m'))
|
||||
->whereYear('created_at', '!=', date('Y'))
|
||||
->whereNull(['reblog_of_id', 'in_reply_to_id'])
|
||||
->limit(20)
|
||||
->pluck('id')
|
||||
->map(function ($id) {
|
||||
return StatusService::get($id, false);
|
||||
})
|
||||
->filter(function ($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
break;
|
||||
|
||||
case 'liked':
|
||||
$res = Like::whereProfileId($pid)
|
||||
->whereDay('created_at', date('d'))
|
||||
->whereMonth('created_at', date('m'))
|
||||
->whereYear('created_at', '!=', date('Y'))
|
||||
->orderByDesc('status_id')
|
||||
->limit(20)
|
||||
->pluck('status_id')
|
||||
->map(function ($id) {
|
||||
$status = StatusService::get($id, false);
|
||||
$status['favourited'] = true;
|
||||
|
||||
return $status;
|
||||
})
|
||||
->filter(function ($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
break;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function accountInsightsPopularPosts(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
abort_if(! $this->config()['insights']['enabled'], 404);
|
||||
$posts = Cache::remember('pf:discover:metro2:accinsights:popular:'.$pid, 43200, function () use ($pid) {
|
||||
return Status::whereProfileId($pid)
|
||||
->whereNotNull('likes_count')
|
||||
->orderByDesc('likes_count')
|
||||
->limit(12)
|
||||
->pluck('id')
|
||||
->map(function ($id) {
|
||||
return StatusService::get($id, false);
|
||||
})
|
||||
->filter(function ($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
});
|
||||
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function config()
|
||||
{
|
||||
$cc = ConfigCacheService::get('config.discover.features');
|
||||
if ($cc) {
|
||||
return is_string($cc) ? json_decode($cc, true) : $cc;
|
||||
}
|
||||
|
||||
return [
|
||||
'hashtags' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'memories' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'insights' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'friends' => [
|
||||
'enabled' => false,
|
||||
],
|
||||
'server' => [
|
||||
'enabled' => false,
|
||||
'mode' => 'allowlist',
|
||||
'domains' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function serverTimeline(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
abort_if(! $this->config()['server']['enabled'], 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
$domain = $request->input('domain');
|
||||
$config = $this->config();
|
||||
$domains = explode(',', $config['server']['domains']);
|
||||
abort_unless(in_array($domain, $domains), 400);
|
||||
|
||||
$res = Status::whereNotNull('uri')
|
||||
->where('uri', 'like', 'https://'.$domain.'%')
|
||||
->whereNull(['in_reply_to_id', 'reblog_of_id'])
|
||||
->orderByDesc('id')
|
||||
->limit(12)
|
||||
->pluck('id')
|
||||
->map(function ($id) {
|
||||
return StatusService::get($id);
|
||||
})
|
||||
->filter(function ($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->values();
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function enabledFeatures(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
|
||||
return $this->config();
|
||||
}
|
||||
|
||||
public function updateFeatures(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
abort_if(! $request->user()->is_admin, 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
$this->validate($request, [
|
||||
'features.friends.enabled' => 'boolean',
|
||||
'features.hashtags.enabled' => 'boolean',
|
||||
'features.insights.enabled' => 'boolean',
|
||||
'features.memories.enabled' => 'boolean',
|
||||
'features.server.enabled' => 'boolean',
|
||||
]);
|
||||
$res = $request->input('features');
|
||||
if ($res['server'] && isset($res['server']['domains']) && ! empty($res['server']['domains'])) {
|
||||
$parts = explode(',', $res['server']['domains']);
|
||||
$parts = array_filter($parts, function ($v) {
|
||||
$len = strlen($v);
|
||||
$pos = strpos($v, '.');
|
||||
$domain = trim($v);
|
||||
if ($pos == false || $pos == ($len + 1)) {
|
||||
return false;
|
||||
}
|
||||
if (! Instance::whereDomain($domain)->exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
$parts = array_slice($parts, 0, 10);
|
||||
$d = implode(',', array_map('trim', $parts));
|
||||
$res['server']['domains'] = $d;
|
||||
}
|
||||
ConfigCacheService::put('config.discover.features', json_encode($res));
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function discoverAccountsPopular(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
|
||||
$ids = Cache::remember('api:v1.1:discover:accounts:popular', 14400, function () {
|
||||
return DB::table('profiles')
|
||||
->where('is_private', false)
|
||||
->whereNull('status')
|
||||
->orderByDesc('profiles.followers_count')
|
||||
->limit(30)
|
||||
->get();
|
||||
});
|
||||
$filters = UserFilterService::filters($pid);
|
||||
$asf = AdminShadowFilterService::getHideFromPublicFeedsList();
|
||||
$ids = $ids->map(function ($profile) {
|
||||
return AccountService::get($profile->id, true);
|
||||
})
|
||||
->filter(function ($profile) {
|
||||
return $profile && isset($profile['id'], $profile['locked']) && ! $profile['locked'];
|
||||
})
|
||||
->filter(function ($profile) use ($pid) {
|
||||
return $profile['id'] != $pid;
|
||||
})
|
||||
->filter(function ($profile) use ($pid) {
|
||||
return ! FollowerService::follows($pid, $profile['id'], true);
|
||||
})
|
||||
->filter(function ($profile) use ($asf) {
|
||||
return ! in_array($profile['id'], $asf);
|
||||
})
|
||||
->filter(function ($profile) use ($filters) {
|
||||
return ! in_array($profile['id'], $filters);
|
||||
})
|
||||
->take(16)
|
||||
->values();
|
||||
|
||||
return response()->json($ids, 200, [], JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,57 +2,42 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\InboxPipeline\{
|
||||
DeleteWorker,
|
||||
InboxWorker,
|
||||
InboxValidator
|
||||
};
|
||||
use App\Jobs\RemoteFollowPipeline\RemoteFollowPipeline;
|
||||
use App\{
|
||||
AccountLog,
|
||||
Like,
|
||||
Profile,
|
||||
Status,
|
||||
User
|
||||
};
|
||||
use App\Util\Lexer\Nickname;
|
||||
use App\Util\Webfinger\Webfinger;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use League\Fractal;
|
||||
use App\Util\Site\Nodeinfo;
|
||||
use App\Util\ActivityPub\{
|
||||
Helpers,
|
||||
HttpSignature,
|
||||
Outbox
|
||||
};
|
||||
use Zttp\Zttp;
|
||||
use App\Services\InstanceService;
|
||||
use App\Jobs\InboxPipeline\DeleteWorker;
|
||||
use App\Jobs\InboxPipeline\InboxValidator;
|
||||
use App\Jobs\InboxPipeline\InboxWorker;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\InstanceService;
|
||||
use App\Status;
|
||||
use App\Util\Lexer\Nickname;
|
||||
use App\Util\Site\Nodeinfo;
|
||||
use App\Util\Webfinger\Webfinger;
|
||||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FederationController extends Controller
|
||||
{
|
||||
public function nodeinfoWellKnown()
|
||||
{
|
||||
abort_if(!config('federation.nodeinfo.enabled'), 404);
|
||||
abort_if(! config('federation.nodeinfo.enabled'), 404);
|
||||
|
||||
return response()->json(Nodeinfo::wellKnown(), 200, [], JSON_UNESCAPED_SLASHES)
|
||||
->header('Access-Control-Allow-Origin','*');
|
||||
->header('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
|
||||
public function nodeinfo()
|
||||
{
|
||||
abort_if(!config('federation.nodeinfo.enabled'), 404);
|
||||
abort_if(! config('federation.nodeinfo.enabled'), 404);
|
||||
|
||||
return response()->json(Nodeinfo::get(), 200, [], JSON_UNESCAPED_SLASHES)
|
||||
->header('Access-Control-Allow-Origin','*');
|
||||
->header('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
|
||||
public function webfinger(Request $request)
|
||||
{
|
||||
if (!config('federation.webfinger.enabled') ||
|
||||
!$request->has('resource') ||
|
||||
!$request->filled('resource')
|
||||
if (! config('federation.webfinger.enabled') ||
|
||||
! $request->has('resource') ||
|
||||
! $request->filled('resource')
|
||||
) {
|
||||
return response('', 400);
|
||||
}
|
||||
|
@ -60,55 +45,56 @@ class FederationController extends Controller
|
|||
$resource = $request->input('resource');
|
||||
$domain = config('pixelfed.domain.app');
|
||||
|
||||
if(config('federation.activitypub.sharedInbox') &&
|
||||
$resource == 'acct:' . $domain . '@' . $domain) {
|
||||
if (config('federation.activitypub.sharedInbox') &&
|
||||
$resource == 'acct:'.$domain.'@'.$domain) {
|
||||
$res = [
|
||||
'subject' => 'acct:' . $domain . '@' . $domain,
|
||||
'subject' => 'acct:'.$domain.'@'.$domain,
|
||||
'aliases' => [
|
||||
'https://' . $domain . '/i/actor'
|
||||
'https://'.$domain.'/i/actor',
|
||||
],
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'http://webfinger.net/rel/profile-page',
|
||||
'type' => 'text/html',
|
||||
'href' => 'https://' . $domain . '/site/kb/instance-actor'
|
||||
'href' => 'https://'.$domain.'/site/kb/instance-actor',
|
||||
],
|
||||
[
|
||||
'rel' => 'self',
|
||||
'type' => 'application/activity+json',
|
||||
'href' => 'https://' . $domain . '/i/actor'
|
||||
]
|
||||
]
|
||||
'href' => 'https://'.$domain.'/i/actor',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
$hash = hash('sha256', $resource);
|
||||
$key = 'federation:webfinger:sha256:' . $hash;
|
||||
if($cached = Cache::get($key)) {
|
||||
$key = 'federation:webfinger:sha256:'.$hash;
|
||||
if ($cached = Cache::get($key)) {
|
||||
return response()->json($cached, 200, [], JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
if(strpos($resource, $domain) == false) {
|
||||
if (strpos($resource, $domain) == false) {
|
||||
return response('', 400);
|
||||
}
|
||||
$parsed = Nickname::normalizeProfileUrl($resource);
|
||||
if(empty($parsed) || $parsed['domain'] !== $domain) {
|
||||
if (empty($parsed) || $parsed['domain'] !== $domain) {
|
||||
return response('', 400);
|
||||
}
|
||||
$username = $parsed['username'];
|
||||
$profile = Profile::whereNull('domain')->whereUsername($username)->first();
|
||||
if(!$profile || $profile->status !== null) {
|
||||
if (! $profile || $profile->status !== null) {
|
||||
return response('', 400);
|
||||
}
|
||||
$webfinger = (new Webfinger($profile))->generate();
|
||||
Cache::put($key, $webfinger, 1209600);
|
||||
|
||||
return response()->json($webfinger, 200, [], JSON_UNESCAPED_SLASHES)
|
||||
->header('Access-Control-Allow-Origin','*');
|
||||
->header('Access-Control-Allow-Origin', '*');
|
||||
}
|
||||
|
||||
public function hostMeta(Request $request)
|
||||
{
|
||||
abort_if(!config('federation.webfinger.enabled'), 404);
|
||||
abort_if(! config('federation.webfinger.enabled'), 404);
|
||||
|
||||
$path = route('well-known.webfinger');
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link rel="lrdd" type="application/xrd+xml" template="'.$path.'?resource={uri}"/></XRD>';
|
||||
|
@ -118,19 +104,19 @@ class FederationController extends Controller
|
|||
|
||||
public function userOutbox(Request $request, $username)
|
||||
{
|
||||
abort_if(!config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
|
||||
|
||||
if(!$request->wantsJson()) {
|
||||
return redirect('/' . $username);
|
||||
if (! $request->wantsJson()) {
|
||||
return redirect('/'.$username);
|
||||
}
|
||||
|
||||
$id = AccountService::usernameToId($username);
|
||||
abort_if(!$id, 404);
|
||||
abort_if(! $id, 404);
|
||||
$account = AccountService::get($id);
|
||||
abort_if(!$account || !isset($account['statuses_count']), 404);
|
||||
abort_if(! $account || ! isset($account['statuses_count']), 404);
|
||||
$res = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => 'https://' . config('pixelfed.domain.app') . '/users/' . $username . '/outbox',
|
||||
'id' => 'https://'.config('pixelfed.domain.app').'/users/'.$username.'/outbox',
|
||||
'type' => 'OrderedCollection',
|
||||
'totalItems' => $account['statuses_count'] ?? 0,
|
||||
];
|
||||
|
@ -140,135 +126,145 @@ class FederationController extends Controller
|
|||
|
||||
public function userInbox(Request $request, $username)
|
||||
{
|
||||
abort_if(!config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(!config('federation.activitypub.inbox'), 404);
|
||||
abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(! config('federation.activitypub.inbox'), 404);
|
||||
|
||||
$headers = $request->headers->all();
|
||||
$payload = $request->getContent();
|
||||
if(!$payload || empty($payload)) {
|
||||
if (! $payload || empty($payload)) {
|
||||
return;
|
||||
}
|
||||
$obj = json_decode($payload, true, 8);
|
||||
if(!isset($obj['id'])) {
|
||||
if (! isset($obj['id'])) {
|
||||
return;
|
||||
}
|
||||
$domain = parse_url($obj['id'], PHP_URL_HOST);
|
||||
if(in_array($domain, InstanceService::getBannedDomains())) {
|
||||
if (in_array($domain, InstanceService::getBannedDomains())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($obj['type']) && $obj['type'] === 'Delete') {
|
||||
if(isset($obj['object']) && isset($obj['object']['type']) && isset($obj['object']['id'])) {
|
||||
if($obj['object']['type'] === 'Person') {
|
||||
if(Profile::whereRemoteUrl($obj['object']['id'])->exists()) {
|
||||
if (isset($obj['type']) && $obj['type'] === 'Delete') {
|
||||
if (isset($obj['object']) && isset($obj['object']['type']) && isset($obj['object']['id'])) {
|
||||
if ($obj['object']['type'] === 'Person') {
|
||||
if (Profile::whereRemoteUrl($obj['object']['id'])->exists()) {
|
||||
dispatch(new DeleteWorker($headers, $payload))->onQueue('inbox');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if($obj['object']['type'] === 'Tombstone') {
|
||||
if(Status::whereObjectUrl($obj['object']['id'])->exists()) {
|
||||
if ($obj['object']['type'] === 'Tombstone') {
|
||||
if (Status::whereObjectUrl($obj['object']['id'])->exists()) {
|
||||
dispatch(new DeleteWorker($headers, $payload))->onQueue('delete');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if($obj['object']['type'] === 'Story') {
|
||||
if ($obj['object']['type'] === 'Story') {
|
||||
dispatch(new DeleteWorker($headers, $payload))->onQueue('story');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} else if( isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) {
|
||||
} elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) {
|
||||
dispatch(new InboxValidator($username, $headers, $payload))->onQueue('follow');
|
||||
} else {
|
||||
dispatch(new InboxValidator($username, $headers, $payload))->onQueue('high');
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public function sharedInbox(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(!config('federation.activitypub.sharedInbox'), 404);
|
||||
abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(! config('federation.activitypub.sharedInbox'), 404);
|
||||
|
||||
$headers = $request->headers->all();
|
||||
$payload = $request->getContent();
|
||||
|
||||
if(!$payload || empty($payload)) {
|
||||
if (! $payload || empty($payload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$obj = json_decode($payload, true, 8);
|
||||
if(!isset($obj['id'])) {
|
||||
if (! isset($obj['id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$domain = parse_url($obj['id'], PHP_URL_HOST);
|
||||
if(in_array($domain, InstanceService::getBannedDomains())) {
|
||||
if (in_array($domain, InstanceService::getBannedDomains())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($obj['type']) && $obj['type'] === 'Delete') {
|
||||
if(isset($obj['object']) && isset($obj['object']['type']) && isset($obj['object']['id'])) {
|
||||
if($obj['object']['type'] === 'Person') {
|
||||
if(Profile::whereRemoteUrl($obj['object']['id'])->exists()) {
|
||||
if (isset($obj['type']) && $obj['type'] === 'Delete') {
|
||||
if (isset($obj['object']) && isset($obj['object']['type']) && isset($obj['object']['id'])) {
|
||||
if ($obj['object']['type'] === 'Person') {
|
||||
if (Profile::whereRemoteUrl($obj['object']['id'])->exists()) {
|
||||
dispatch(new DeleteWorker($headers, $payload))->onQueue('inbox');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if($obj['object']['type'] === 'Tombstone') {
|
||||
if(Status::whereObjectUrl($obj['object']['id'])->exists()) {
|
||||
if ($obj['object']['type'] === 'Tombstone') {
|
||||
if (Status::whereObjectUrl($obj['object']['id'])->exists()) {
|
||||
dispatch(new DeleteWorker($headers, $payload))->onQueue('delete');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if($obj['object']['type'] === 'Story') {
|
||||
if ($obj['object']['type'] === 'Story') {
|
||||
dispatch(new DeleteWorker($headers, $payload))->onQueue('story');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} else if( isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) {
|
||||
} elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) {
|
||||
dispatch(new InboxWorker($headers, $payload))->onQueue('follow');
|
||||
} else {
|
||||
dispatch(new InboxWorker($headers, $payload))->onQueue('shared');
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
public function userFollowing(Request $request, $username)
|
||||
{
|
||||
abort_if(!config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
|
||||
|
||||
$id = AccountService::usernameToId($username);
|
||||
abort_if(!$id, 404);
|
||||
abort_if(! $id, 404);
|
||||
$account = AccountService::get($id);
|
||||
abort_if(!$account || !isset($account['following_count']), 404);
|
||||
abort_if(! $account || ! isset($account['following_count']), 404);
|
||||
$obj = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $request->getUri(),
|
||||
'type' => 'OrderedCollection',
|
||||
'id' => $request->getUri(),
|
||||
'type' => 'OrderedCollection',
|
||||
'totalItems' => $account['following_count'] ?? 0,
|
||||
];
|
||||
return response()->json($obj);
|
||||
|
||||
return response()->json($obj)->header('Content-Type', 'application/activity+json');
|
||||
}
|
||||
|
||||
public function userFollowers(Request $request, $username)
|
||||
{
|
||||
abort_if(!config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(! (bool) config_cache('federation.activitypub.enabled'), 404);
|
||||
$id = AccountService::usernameToId($username);
|
||||
abort_if(!$id, 404);
|
||||
abort_if(! $id, 404);
|
||||
$account = AccountService::get($id);
|
||||
abort_if(!$account || !isset($account['followers_count']), 404);
|
||||
abort_if(! $account || ! isset($account['followers_count']), 404);
|
||||
$obj = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $request->getUri(),
|
||||
'type' => 'OrderedCollection',
|
||||
'id' => $request->getUri(),
|
||||
'type' => 'OrderedCollection',
|
||||
'totalItems' => $account['followers_count'] ?? 0,
|
||||
];
|
||||
return response()->json($obj);
|
||||
|
||||
return response()->json($obj)->header('Content-Type', 'application/activity+json');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ trait Instagram
|
|||
{
|
||||
public function instagram()
|
||||
{
|
||||
if(config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
return view('settings.import.instagram.home');
|
||||
|
@ -25,6 +25,9 @@ trait Instagram
|
|||
|
||||
public function instagramStart(Request $request)
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$completed = ImportJob::whereProfileId(Auth::user()->profile->id)
|
||||
->whereService('instagram')
|
||||
->whereNotNull('completed_at')
|
||||
|
@ -38,6 +41,9 @@ trait Instagram
|
|||
|
||||
protected function instagramRedirectOrNew()
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$profile = Auth::user()->profile;
|
||||
$exists = ImportJob::whereProfileId($profile->id)
|
||||
->whereService('instagram')
|
||||
|
@ -61,6 +67,9 @@ trait Instagram
|
|||
|
||||
public function instagramStepOne(Request $request, $uuid)
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$profile = Auth::user()->profile;
|
||||
$job = ImportJob::whereProfileId($profile->id)
|
||||
->whereNull('completed_at')
|
||||
|
@ -72,6 +81,9 @@ trait Instagram
|
|||
|
||||
public function instagramStepOneStore(Request $request, $uuid)
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$max = 'max:' . config('pixelfed.import.instagram.limits.size');
|
||||
$this->validate($request, [
|
||||
'media.*' => 'required|mimes:bin,jpeg,png,gif|'.$max,
|
||||
|
@ -114,6 +126,9 @@ trait Instagram
|
|||
|
||||
public function instagramStepTwo(Request $request, $uuid)
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$profile = Auth::user()->profile;
|
||||
$job = ImportJob::whereProfileId($profile->id)
|
||||
->whereNull('completed_at')
|
||||
|
@ -125,6 +140,9 @@ trait Instagram
|
|||
|
||||
public function instagramStepTwoStore(Request $request, $uuid)
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$this->validate($request, [
|
||||
'media' => 'required|file|max:1000'
|
||||
]);
|
||||
|
@ -150,6 +168,9 @@ trait Instagram
|
|||
|
||||
public function instagramStepThree(Request $request, $uuid)
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$profile = Auth::user()->profile;
|
||||
$job = ImportJob::whereProfileId($profile->id)
|
||||
->whereService('instagram')
|
||||
|
@ -162,6 +183,9 @@ trait Instagram
|
|||
|
||||
public function instagramStepThreeStore(Request $request, $uuid)
|
||||
{
|
||||
if((bool) config_cache('pixelfed.import.instagram.enabled') != true) {
|
||||
abort(404, 'Feature not enabled');
|
||||
}
|
||||
$profile = Auth::user()->profile;
|
||||
|
||||
try {
|
||||
|
|
|
@ -179,7 +179,7 @@ class ImportPostController extends Controller
|
|||
'required',
|
||||
'file',
|
||||
$mimes,
|
||||
'max:' . config('pixelfed.max_photo_size')
|
||||
'max:' . config_cache('pixelfed.max_photo_size')
|
||||
]
|
||||
]);
|
||||
|
||||
|
|
|
@ -2,44 +2,43 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use App\Http\Resources\DirectoryProfile;
|
||||
use App\Profile;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LandingController extends Controller
|
||||
{
|
||||
public function directoryRedirect(Request $request)
|
||||
{
|
||||
if($request->user()) {
|
||||
return redirect('/');
|
||||
}
|
||||
if ($request->user()) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
abort_if(config_cache('instance.landing.show_directory') == false, 404);
|
||||
abort_if((bool) config_cache('instance.landing.show_directory') == false, 404);
|
||||
|
||||
return view('site.index');
|
||||
return view('site.index');
|
||||
}
|
||||
|
||||
public function exploreRedirect(Request $request)
|
||||
{
|
||||
if($request->user()) {
|
||||
return redirect('/');
|
||||
}
|
||||
if ($request->user()) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
abort_if(config_cache('instance.landing.show_explore') == false, 404);
|
||||
abort_if((bool) config_cache('instance.landing.show_explore') == false, 404);
|
||||
|
||||
return view('site.index');
|
||||
return view('site.index');
|
||||
}
|
||||
|
||||
public function getDirectoryApi(Request $request)
|
||||
{
|
||||
abort_if(config_cache('instance.landing.show_directory') == false, 404);
|
||||
abort_if((bool) config_cache('instance.landing.show_directory') == false, 404);
|
||||
|
||||
return DirectoryProfile::collection(
|
||||
Profile::whereNull('domain')
|
||||
->whereIsSuggestable(true)
|
||||
->orderByDesc('updated_at')
|
||||
->cursorPaginate(20)
|
||||
);
|
||||
return DirectoryProfile::collection(
|
||||
Profile::whereNull('domain')
|
||||
->whereIsSuggestable(true)
|
||||
->orderByDesc('updated_at')
|
||||
->cursorPaginate(20)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,30 +2,31 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Media;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MediaController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
//return view('settings.drive.index');
|
||||
}
|
||||
public function index(Request $request)
|
||||
{
|
||||
//return view('settings.drive.index');
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function composeUpdate(Request $request, $id)
|
||||
{
|
||||
public function composeUpdate(Request $request, $id)
|
||||
{
|
||||
abort(400, 'Endpoint deprecated');
|
||||
}
|
||||
}
|
||||
|
||||
public function fallbackRedirect(Request $request, $pid, $mhash, $uhash, $f)
|
||||
{
|
||||
abort_if(!config_cache('pixelfed.cloud_storage'), 404);
|
||||
$path = 'public/m/_v2/' . $pid . '/' . $mhash . '/' . $uhash . '/' . $f;
|
||||
$media = Media::whereProfileId($pid)
|
||||
->whereMediaPath($path)
|
||||
->whereNotNull('cdn_url')
|
||||
->firstOrFail();
|
||||
public function fallbackRedirect(Request $request, $pid, $mhash, $uhash, $f)
|
||||
{
|
||||
abort_if(! (bool) config_cache('pixelfed.cloud_storage'), 404);
|
||||
$path = 'public/m/_v2/'.$pid.'/'.$mhash.'/'.$uhash.'/'.$f;
|
||||
$media = Media::whereProfileId($pid)
|
||||
->whereMediaPath($path)
|
||||
->whereNotNull('cdn_url')
|
||||
->firstOrFail();
|
||||
|
||||
return redirect()->away($media->cdn_url);
|
||||
}
|
||||
return redirect()->away($media->cdn_url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,37 +2,41 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ConfigCache;
|
||||
use Storage;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\StatusService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Cache;
|
||||
use Storage;
|
||||
use App\Status;
|
||||
use App\User;
|
||||
|
||||
class PixelfedDirectoryController extends Controller
|
||||
{
|
||||
public function get(Request $request)
|
||||
{
|
||||
if(!$request->filled('sk')) {
|
||||
if (! $request->filled('sk')) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if(!config_cache('pixelfed.directory.submission-key')) {
|
||||
if (! config_cache('pixelfed.directory.submission-key')) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if(!hash_equals(config_cache('pixelfed.directory.submission-key'), $request->input('sk'))) {
|
||||
if (! hash_equals(config_cache('pixelfed.directory.submission-key'), $request->input('sk'))) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$res = $this->buildListing();
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
public function buildListing()
|
||||
{
|
||||
$res = config_cache('pixelfed.directory');
|
||||
if($res) {
|
||||
if ($res) {
|
||||
$res = is_string($res) ? json_decode($res, true) : $res;
|
||||
}
|
||||
|
||||
|
@ -41,70 +45,71 @@ class PixelfedDirectoryController extends Controller
|
|||
$res['_ts'] = config_cache('pixelfed.directory.submission-ts');
|
||||
$res['version'] = config_cache('pixelfed.version');
|
||||
|
||||
if(empty($res['summary'])) {
|
||||
if (empty($res['summary'])) {
|
||||
$summary = ConfigCache::whereK('app.short_description')->pluck('v');
|
||||
$res['summary'] = $summary ? $summary[0] : null;
|
||||
}
|
||||
|
||||
if(isset($res['admin'])) {
|
||||
if (isset($res['admin'])) {
|
||||
$res['admin'] = AccountService::get($res['admin'], true);
|
||||
}
|
||||
|
||||
if(isset($res['banner_image']) && !empty($res['banner_image'])) {
|
||||
if (isset($res['banner_image']) && ! empty($res['banner_image'])) {
|
||||
$res['banner_image'] = url(Storage::url($res['banner_image']));
|
||||
}
|
||||
|
||||
if(isset($res['favourite_posts'])) {
|
||||
$res['favourite_posts'] = collect($res['favourite_posts'])->map(function($id) {
|
||||
if (isset($res['favourite_posts'])) {
|
||||
$res['favourite_posts'] = collect($res['favourite_posts'])->map(function ($id) {
|
||||
return StatusService::get($id);
|
||||
})
|
||||
->filter(function($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->map(function($post) {
|
||||
return [
|
||||
'avatar' => $post['account']['avatar'],
|
||||
'display_name' => $post['account']['display_name'],
|
||||
'username' => $post['account']['username'],
|
||||
'media' => $post['media_attachments'][0]['url'],
|
||||
'url' => $post['url']
|
||||
];
|
||||
})
|
||||
->values();
|
||||
->filter(function ($post) {
|
||||
return $post && isset($post['account']);
|
||||
})
|
||||
->map(function ($post) {
|
||||
return [
|
||||
'avatar' => $post['account']['avatar'],
|
||||
'display_name' => $post['account']['display_name'],
|
||||
'username' => $post['account']['username'],
|
||||
'media' => $post['media_attachments'][0]['url'],
|
||||
'url' => $post['url'],
|
||||
];
|
||||
})
|
||||
->values();
|
||||
}
|
||||
|
||||
$guidelines = ConfigCache::whereK('app.rules')->first();
|
||||
if($guidelines) {
|
||||
if ($guidelines) {
|
||||
$res['community_guidelines'] = json_decode($guidelines->v, true);
|
||||
}
|
||||
|
||||
$openRegistration = ConfigCache::whereK('pixelfed.open_registration')->first();
|
||||
if($openRegistration) {
|
||||
$res['open_registration'] = (bool) $openRegistration;
|
||||
}
|
||||
$openRegistration = (bool) config_cache('pixelfed.open_registration');
|
||||
$res['open_registration'] = $openRegistration;
|
||||
|
||||
$curatedOnboarding = (bool) config_cache('instance.curated_registration.enabled');
|
||||
$res['curated_onboarding'] = $curatedOnboarding;
|
||||
|
||||
$oauthEnabled = ConfigCache::whereK('pixelfed.oauth_enabled')->first();
|
||||
if($oauthEnabled) {
|
||||
if ($oauthEnabled) {
|
||||
$keys = file_exists(storage_path('oauth-public.key')) && file_exists(storage_path('oauth-private.key'));
|
||||
$res['oauth_enabled'] = (bool) $oauthEnabled && $keys;
|
||||
}
|
||||
|
||||
$activityPubEnabled = ConfigCache::whereK('federation.activitypub.enabled')->first();
|
||||
if($activityPubEnabled) {
|
||||
if ($activityPubEnabled) {
|
||||
$res['activitypub_enabled'] = (bool) $activityPubEnabled;
|
||||
}
|
||||
|
||||
$res['feature_config'] = [
|
||||
'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','),
|
||||
'image_quality' => config_cache('pixelfed.image_quality'),
|
||||
'optimize_image' => config_cache('pixelfed.optimize_image'),
|
||||
'optimize_image' => (bool) config_cache('pixelfed.optimize_image'),
|
||||
'max_photo_size' => config_cache('pixelfed.max_photo_size'),
|
||||
'max_caption_length' => config_cache('pixelfed.max_caption_length'),
|
||||
'max_altext_length' => config_cache('pixelfed.max_altext_length'),
|
||||
'enforce_account_limit' => config_cache('pixelfed.enforce_account_limit'),
|
||||
'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit'),
|
||||
'max_account_size' => config_cache('pixelfed.max_account_size'),
|
||||
'max_album_length' => config_cache('pixelfed.max_album_length'),
|
||||
'account_deletion' => config_cache('pixelfed.account_deletion'),
|
||||
'account_deletion' => (bool) config_cache('pixelfed.account_deletion'),
|
||||
];
|
||||
|
||||
$res['is_eligible'] = $this->validVal($res, 'admin') &&
|
||||
|
@ -114,29 +119,36 @@ class PixelfedDirectoryController extends Controller
|
|||
$this->validVal($res, 'privacy_pledge') &&
|
||||
$this->validVal($res, 'location');
|
||||
|
||||
if(config_cache('pixelfed.directory.testimonials')) {
|
||||
if (config_cache('pixelfed.directory.testimonials')) {
|
||||
$res['testimonials'] = collect(json_decode(config_cache('pixelfed.directory.testimonials'), true))
|
||||
->map(function($testimonial) {
|
||||
->map(function ($testimonial) {
|
||||
$profile = AccountService::get($testimonial['profile_id']);
|
||||
|
||||
return [
|
||||
'profile' => [
|
||||
'username' => $profile['username'],
|
||||
'display_name' => $profile['display_name'],
|
||||
'avatar' => $profile['avatar'],
|
||||
'created_at' => $profile['created_at']
|
||||
'created_at' => $profile['created_at'],
|
||||
],
|
||||
'body' => $testimonial['body']
|
||||
'body' => $testimonial['body'],
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$res['features_enabled'] = [
|
||||
'stories' => (bool) config_cache('instance.stories.enabled')
|
||||
'stories' => (bool) config_cache('instance.stories.enabled'),
|
||||
];
|
||||
|
||||
$statusesCount = Cache::remember('api:nodeinfo:statuses', 21600, function() {
|
||||
return Status::whereLocal(true)->count();
|
||||
});
|
||||
$usersCount = Cache::remember('api:nodeinfo:users', 43200, function() {
|
||||
return User::count();
|
||||
});
|
||||
$res['stats'] = [
|
||||
'user_count' => \App\User::count(),
|
||||
'post_count' => \App\Status::whereNull('uri')->count(),
|
||||
'user_count' => (int) $usersCount,
|
||||
'post_count' => (int) $statusesCount,
|
||||
];
|
||||
|
||||
$res['primary_locale'] = config('app.locale');
|
||||
|
@ -149,19 +161,18 @@ class PixelfedDirectoryController extends Controller
|
|||
|
||||
protected function validVal($res, $val, $count = false, $minLen = false)
|
||||
{
|
||||
if(!isset($res[$val])) {
|
||||
if (! isset($res[$val])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($count) {
|
||||
if ($count) {
|
||||
return count($res[$val]) >= $count;
|
||||
}
|
||||
|
||||
if($minLen) {
|
||||
if ($minLen) {
|
||||
return strlen($res[$val]) >= $minLen;
|
||||
}
|
||||
|
||||
return $res[$val];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,11 +2,13 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Util\Lexer\Nickname;
|
||||
use App\Util\Webfinger\WebfingerUrl;
|
||||
use App\Models\ProfileAlias;
|
||||
use App\Models\ProfileMigration;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\WebfingerService;
|
||||
use App\Util\Lexer\Nickname;
|
||||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProfileAliasController extends Controller
|
||||
{
|
||||
|
@ -18,31 +20,47 @@ class ProfileAliasController extends Controller
|
|||
public function index(Request $request)
|
||||
{
|
||||
$aliases = $request->user()->profile->aliases;
|
||||
|
||||
return view('settings.aliases.index', compact('aliases'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'acct' => 'required'
|
||||
'acct' => 'required',
|
||||
]);
|
||||
|
||||
$acct = $request->input('acct');
|
||||
|
||||
if($request->user()->profile->aliases->count() >= 3) {
|
||||
$nn = Nickname::normalizeProfileUrl($acct);
|
||||
if (! $nn) {
|
||||
return back()->with('error', 'Invalid account alias.');
|
||||
}
|
||||
|
||||
if ($nn['domain'] === config('pixelfed.domain.app')) {
|
||||
if (strtolower($nn['username']) == ($request->user()->username)) {
|
||||
return back()->with('error', 'You cannot add an alias to your own account.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->user()->profile->aliases->count() >= 3) {
|
||||
return back()->with('error', 'You can only add 3 account aliases.');
|
||||
}
|
||||
|
||||
$webfingerService = WebfingerService::lookup($acct);
|
||||
if(!$webfingerService || !isset($webfingerService['url'])) {
|
||||
$webfingerUrl = WebfingerService::rawGet($acct);
|
||||
|
||||
if (! $webfingerService || ! isset($webfingerService['url']) || ! $webfingerUrl || empty($webfingerUrl)) {
|
||||
return back()->with('error', 'Invalid account, cannot add alias at this time.');
|
||||
}
|
||||
$alias = new ProfileAlias;
|
||||
$alias->profile_id = $request->user()->profile_id;
|
||||
$alias->acct = $acct;
|
||||
$alias->uri = $webfingerService['url'];
|
||||
$alias->uri = $webfingerUrl;
|
||||
$alias->save();
|
||||
|
||||
Cache::forget('pf:activitypub:user-object:by-id:'.$request->user()->profile_id);
|
||||
|
||||
return back()->with('status', 'Successfully added alias!');
|
||||
}
|
||||
|
||||
|
@ -50,14 +68,25 @@ class ProfileAliasController extends Controller
|
|||
{
|
||||
$this->validate($request, [
|
||||
'acct' => 'required',
|
||||
'id' => 'required|exists:profile_aliases'
|
||||
'id' => 'required|exists:profile_aliases',
|
||||
]);
|
||||
|
||||
$alias = ProfileAlias::where('profile_id', $request->user()->profile_id)
|
||||
->where('acct', $request->input('acct'))
|
||||
$pid = $request->user()->profile_id;
|
||||
$acct = $request->input('acct');
|
||||
$alias = ProfileAlias::where('profile_id', $pid)
|
||||
->where('acct', $acct)
|
||||
->findOrFail($request->input('id'));
|
||||
$migration = ProfileMigration::whereProfileId($pid)
|
||||
->whereAcct($acct)
|
||||
->first();
|
||||
if ($migration) {
|
||||
$request->user()->profile->update([
|
||||
'moved_to_profile_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
$alias->delete();
|
||||
Cache::forget('pf:activitypub:user-object:by-id:'.$pid);
|
||||
AccountService::del($pid);
|
||||
|
||||
return back()->with('status', 'Successfully deleted alias!');
|
||||
}
|
||||
|
|
|
@ -2,356 +2,387 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use DB;
|
||||
use View;
|
||||
use App\AccountInterstitial;
|
||||
use App\Follower;
|
||||
use App\FollowRequest;
|
||||
use App\Profile;
|
||||
use App\Story;
|
||||
use App\Status;
|
||||
use App\User;
|
||||
use App\UserSetting;
|
||||
use App\UserFilter;
|
||||
use League\Fractal;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\StatusService;
|
||||
use App\Util\Lexer\Nickname;
|
||||
use App\Util\Webfinger\Webfinger;
|
||||
use App\Transformer\ActivityPub\ProfileOutbox;
|
||||
use App\Status;
|
||||
use App\Story;
|
||||
use App\Transformer\ActivityPub\ProfileTransformer;
|
||||
use App\User;
|
||||
use App\UserFilter;
|
||||
use App\UserSetting;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use League\Fractal;
|
||||
use View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
public function show(Request $request, $username)
|
||||
{
|
||||
// redirect authed users to Metro 2.0
|
||||
if($request->user()) {
|
||||
// unless they force static view
|
||||
if(!$request->has('fs') || $request->input('fs') != '1') {
|
||||
$pid = AccountService::usernameToId($username);
|
||||
if($pid) {
|
||||
return redirect('/i/web/profile/' . $pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function show(Request $request, $username)
|
||||
{
|
||||
if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
|
||||
$user = $this->getCachedUser($username, true);
|
||||
abort_if(! $user, 404, 'Not found');
|
||||
|
||||
$user = Profile::whereNull('domain')
|
||||
->whereNull('status')
|
||||
->whereUsername($username)
|
||||
->firstOrFail();
|
||||
return $this->showActivityPub($request, $user);
|
||||
}
|
||||
|
||||
// redirect authed users to Metro 2.0
|
||||
if ($request->user()) {
|
||||
// unless they force static view
|
||||
if (! $request->has('fs') || $request->input('fs') != '1') {
|
||||
$pid = AccountService::usernameToId($username);
|
||||
if ($pid) {
|
||||
return redirect('/i/web/profile/'.$pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($request->wantsJson() && config_cache('federation.activitypub.enabled')) {
|
||||
return $this->showActivityPub($request, $user);
|
||||
}
|
||||
$user = $this->getCachedUser($username);
|
||||
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:' . $user->id, 86400, function() use($user) {
|
||||
$exists = AccountInterstitial::whereUserId($user->user_id)->where('is_spam', 1)->count();
|
||||
if($exists) {
|
||||
return true;
|
||||
}
|
||||
abort_unless($user, 404);
|
||||
|
||||
return false;
|
||||
});
|
||||
if($aiCheck) {
|
||||
return redirect('/login');
|
||||
}
|
||||
return $this->buildProfile($request, $user);
|
||||
}
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:'.$user->id, 3600, function () use ($user) {
|
||||
$exists = AccountInterstitial::whereUserId($user->user_id)->where('is_spam', 1)->count();
|
||||
if ($exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function buildProfile(Request $request, $user)
|
||||
{
|
||||
$username = $user->username;
|
||||
$loggedIn = Auth::check();
|
||||
$isPrivate = false;
|
||||
$isBlocked = false;
|
||||
if(!$loggedIn) {
|
||||
$key = 'profile:settings:' . $user->id;
|
||||
$ttl = now()->addHours(6);
|
||||
$settings = Cache::remember($key, $ttl, function() use($user) {
|
||||
return $user->user->settings;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
if ($aiCheck) {
|
||||
return redirect('/login');
|
||||
}
|
||||
|
||||
if ($user->is_private == true) {
|
||||
$profile = null;
|
||||
return view('profile.private', compact('user'));
|
||||
}
|
||||
return $this->buildProfile($request, $user);
|
||||
}
|
||||
|
||||
$owner = false;
|
||||
$is_following = false;
|
||||
protected function buildProfile(Request $request, $user)
|
||||
{
|
||||
$username = $user->username;
|
||||
$loggedIn = Auth::check();
|
||||
$isPrivate = false;
|
||||
$isBlocked = false;
|
||||
if (! $loggedIn) {
|
||||
$key = 'profile:settings:'.$user->id;
|
||||
$ttl = now()->addHours(6);
|
||||
$settings = Cache::remember($key, $ttl, function () use ($user) {
|
||||
return $user->user->settings;
|
||||
});
|
||||
|
||||
$profile = $user;
|
||||
$settings = [
|
||||
'crawlable' => $settings->crawlable,
|
||||
'following' => [
|
||||
'count' => $settings->show_profile_following_count,
|
||||
'list' => $settings->show_profile_following
|
||||
],
|
||||
'followers' => [
|
||||
'count' => $settings->show_profile_follower_count,
|
||||
'list' => $settings->show_profile_followers
|
||||
]
|
||||
];
|
||||
return view('profile.show', compact('profile', 'settings'));
|
||||
} else {
|
||||
$key = 'profile:settings:' . $user->id;
|
||||
$ttl = now()->addHours(6);
|
||||
$settings = Cache::remember($key, $ttl, function() use($user) {
|
||||
return $user->user->settings;
|
||||
});
|
||||
if ($user->is_private == true) {
|
||||
$profile = null;
|
||||
|
||||
if ($user->is_private == true) {
|
||||
$isPrivate = $this->privateProfileCheck($user, $loggedIn);
|
||||
}
|
||||
return view('profile.private', compact('user'));
|
||||
}
|
||||
|
||||
$isBlocked = $this->blockedProfileCheck($user);
|
||||
$owner = false;
|
||||
$is_following = false;
|
||||
|
||||
$owner = $loggedIn && Auth::id() === $user->user_id;
|
||||
$is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
|
||||
$profile = $user;
|
||||
$settings = [
|
||||
'crawlable' => $settings->crawlable,
|
||||
'following' => [
|
||||
'count' => $settings->show_profile_following_count,
|
||||
'list' => $settings->show_profile_following,
|
||||
],
|
||||
'followers' => [
|
||||
'count' => $settings->show_profile_follower_count,
|
||||
'list' => $settings->show_profile_followers,
|
||||
],
|
||||
];
|
||||
|
||||
if ($isPrivate == true || $isBlocked == true) {
|
||||
$requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id)
|
||||
->whereFollowingId($user->id)
|
||||
->exists() : false;
|
||||
return view('profile.private', compact('user', 'is_following', 'requested'));
|
||||
}
|
||||
return view('profile.show', compact('profile', 'settings'));
|
||||
} else {
|
||||
$key = 'profile:settings:'.$user->id;
|
||||
$ttl = now()->addHours(6);
|
||||
$settings = Cache::remember($key, $ttl, function () use ($user) {
|
||||
return $user->user->settings;
|
||||
});
|
||||
|
||||
$is_admin = is_null($user->domain) ? $user->user->is_admin : false;
|
||||
$profile = $user;
|
||||
$settings = [
|
||||
'crawlable' => $settings->crawlable,
|
||||
'following' => [
|
||||
'count' => $settings->show_profile_following_count,
|
||||
'list' => $settings->show_profile_following
|
||||
],
|
||||
'followers' => [
|
||||
'count' => $settings->show_profile_follower_count,
|
||||
'list' => $settings->show_profile_followers
|
||||
]
|
||||
];
|
||||
return view('profile.show', compact('profile', 'settings'));
|
||||
}
|
||||
}
|
||||
if ($user->is_private == true) {
|
||||
$isPrivate = $this->privateProfileCheck($user, $loggedIn);
|
||||
}
|
||||
|
||||
public function permalinkRedirect(Request $request, $username)
|
||||
{
|
||||
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||
$isBlocked = $this->blockedProfileCheck($user);
|
||||
|
||||
if ($request->wantsJson() && config_cache('federation.activitypub.enabled')) {
|
||||
return $this->showActivityPub($request, $user);
|
||||
}
|
||||
$owner = $loggedIn && Auth::id() === $user->user_id;
|
||||
$is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
|
||||
|
||||
return redirect($user->url());
|
||||
}
|
||||
if ($isPrivate == true || $isBlocked == true) {
|
||||
$requested = Auth::check() ? FollowRequest::whereFollowerId(Auth::user()->profile_id)
|
||||
->whereFollowingId($user->id)
|
||||
->exists() : false;
|
||||
|
||||
protected function privateProfileCheck(Profile $profile, $loggedIn)
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return true;
|
||||
}
|
||||
return view('profile.private', compact('user', 'is_following', 'requested'));
|
||||
}
|
||||
|
||||
$user = Auth::user()->profile;
|
||||
if($user->id == $profile->id || !$profile->is_private) {
|
||||
return false;
|
||||
}
|
||||
$is_admin = is_null($user->domain) ? $user->user->is_admin : false;
|
||||
$profile = $user;
|
||||
$settings = [
|
||||
'crawlable' => $settings->crawlable,
|
||||
'following' => [
|
||||
'count' => $settings->show_profile_following_count,
|
||||
'list' => $settings->show_profile_following,
|
||||
],
|
||||
'followers' => [
|
||||
'count' => $settings->show_profile_follower_count,
|
||||
'list' => $settings->show_profile_followers,
|
||||
],
|
||||
];
|
||||
|
||||
$follows = Follower::whereProfileId($user->id)->whereFollowingId($profile->id)->exists();
|
||||
if ($follows == false) {
|
||||
return true;
|
||||
}
|
||||
return view('profile.show', compact('profile', 'settings'));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
protected function getCachedUser($username, $withTrashed = false)
|
||||
{
|
||||
$val = str_replace(['_', '.', '-'], '', $username);
|
||||
if (! ctype_alnum($val)) {
|
||||
return;
|
||||
}
|
||||
$hash = ($withTrashed ? 'wt:' : 'wot:').strtolower($username);
|
||||
|
||||
public static function accountCheck(Profile $profile)
|
||||
{
|
||||
switch ($profile->status) {
|
||||
case 'disabled':
|
||||
case 'suspended':
|
||||
case 'delete':
|
||||
return view('profile.disabled');
|
||||
break;
|
||||
return Cache::remember('pfc:cached-user:'.$hash, ($withTrashed ? 14400 : 900), function () use ($username, $withTrashed) {
|
||||
if (! $withTrashed) {
|
||||
return Profile::whereNull(['domain', 'status'])
|
||||
->whereUsername($username)
|
||||
->first();
|
||||
} else {
|
||||
return Profile::withTrashed()
|
||||
->whereNull('domain')
|
||||
->whereUsername($username)
|
||||
->first();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return abort(404);
|
||||
}
|
||||
public function permalinkRedirect(Request $request, $username)
|
||||
{
|
||||
if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
|
||||
$user = $this->getCachedUser($username, true);
|
||||
|
||||
protected function blockedProfileCheck(Profile $profile)
|
||||
{
|
||||
$pid = Auth::user()->profile->id;
|
||||
$blocks = UserFilter::whereUserId($profile->id)
|
||||
->whereFilterType('block')
|
||||
->whereFilterableType('App\Profile')
|
||||
->pluck('filterable_id')
|
||||
->toArray();
|
||||
if (in_array($pid, $blocks)) {
|
||||
return true;
|
||||
}
|
||||
return $this->showActivityPub($request, $user);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
$user = $this->getCachedUser($username);
|
||||
|
||||
public function showActivityPub(Request $request, $user)
|
||||
{
|
||||
abort_if(!config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if($user->domain, 404);
|
||||
abort_if(! $user, 404);
|
||||
|
||||
return Cache::remember('pf:activitypub:user-object:by-id:' . $user->id, 3600, function() use($user) {
|
||||
$fractal = new Fractal\Manager();
|
||||
$resource = new Fractal\Resource\Item($user, new ProfileTransformer);
|
||||
$res = $fractal->createData($resource)->toArray();
|
||||
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
|
||||
});
|
||||
}
|
||||
return redirect($user->url());
|
||||
}
|
||||
|
||||
public function showAtomFeed(Request $request, $user)
|
||||
{
|
||||
abort_if(!config('federation.atom.enabled'), 404);
|
||||
protected function privateProfileCheck(Profile $profile, $loggedIn)
|
||||
{
|
||||
if (! Auth::check()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$pid = AccountService::usernameToId($user);
|
||||
$user = Auth::user()->profile;
|
||||
if ($user->id == $profile->id || ! $profile->is_private) {
|
||||
return false;
|
||||
}
|
||||
|
||||
abort_if(!$pid, 404);
|
||||
$follows = Follower::whereProfileId($user->id)->whereFollowingId($profile->id)->exists();
|
||||
if ($follows == false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$profile = AccountService::get($pid, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
abort_if(!$profile || $profile['locked'] || !$profile['local'], 404);
|
||||
public static function accountCheck(Profile $profile)
|
||||
{
|
||||
switch ($profile->status) {
|
||||
case 'disabled':
|
||||
case 'suspended':
|
||||
case 'delete':
|
||||
return view('profile.disabled');
|
||||
break;
|
||||
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:' . $profile['id'], 86400, function() use($profile) {
|
||||
$uid = User::whereProfileId($profile['id'])->first();
|
||||
if(!$uid) {
|
||||
return true;
|
||||
}
|
||||
$exists = AccountInterstitial::whereUserId($uid->id)->where('is_spam', 1)->count();
|
||||
if($exists) {
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
return abort(404);
|
||||
}
|
||||
|
||||
abort_if($aiCheck, 404);
|
||||
protected function blockedProfileCheck(Profile $profile)
|
||||
{
|
||||
$pid = Auth::user()->profile->id;
|
||||
$blocks = UserFilter::whereUserId($profile->id)
|
||||
->whereFilterType('block')
|
||||
->whereFilterableType('App\Profile')
|
||||
->pluck('filterable_id')
|
||||
->toArray();
|
||||
if (in_array($pid, $blocks)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$enabled = Cache::remember('profile:atom:enabled:' . $profile['id'], 84600, function() use ($profile) {
|
||||
$uid = User::whereProfileId($profile['id'])->first();
|
||||
if(!$uid) {
|
||||
return false;
|
||||
}
|
||||
$settings = UserSetting::whereUserId($uid->id)->first();
|
||||
if(!$settings) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return $settings->show_atom;
|
||||
});
|
||||
public function showActivityPub(Request $request, $user)
|
||||
{
|
||||
abort_if(! config_cache('federation.activitypub.enabled'), 404);
|
||||
abort_if(! $user, 404, 'Not found');
|
||||
abort_if($user->domain, 404);
|
||||
|
||||
abort_if(!$enabled, 404);
|
||||
return Cache::remember('pf:activitypub:user-object:by-id:'.$user->id, 1800, function () use ($user) {
|
||||
$fractal = new Fractal\Manager();
|
||||
$resource = new Fractal\Resource\Item($user, new ProfileTransformer);
|
||||
$res = $fractal->createData($resource)->toArray();
|
||||
|
||||
$data = Cache::remember('pf:atom:user-feed:by-id:' . $profile['id'], 900, function() use($pid, $profile) {
|
||||
$items = Status::whereProfileId($pid)
|
||||
->whereScope('public')
|
||||
->whereIn('type', ['photo', 'photo:album'])
|
||||
->orderByDesc('id')
|
||||
->take(10)
|
||||
->get()
|
||||
->map(function($status) {
|
||||
return StatusService::get($status->id, true);
|
||||
})
|
||||
->filter(function($status) {
|
||||
return $status &&
|
||||
isset($status['account']) &&
|
||||
isset($status['media_attachments']) &&
|
||||
count($status['media_attachments']);
|
||||
})
|
||||
->values();
|
||||
$permalink = config('app.url') . "/users/{$profile['username']}.atom";
|
||||
$headers = ['Content-Type' => 'application/atom+xml'];
|
||||
return response(json_encode($res['data']))->header('Content-Type', 'application/activity+json');
|
||||
});
|
||||
}
|
||||
|
||||
if($items && $items->count()) {
|
||||
$headers['Last-Modified'] = now()->parse($items->first()['created_at'])->toRfc7231String();
|
||||
}
|
||||
public function showAtomFeed(Request $request, $user)
|
||||
{
|
||||
abort_if(! config('federation.atom.enabled'), 404);
|
||||
|
||||
return compact('items', 'permalink', 'headers');
|
||||
});
|
||||
abort_if(!$data || !isset($data['items']) || !isset($data['permalink']), 404);
|
||||
return response()
|
||||
->view('atom.user',
|
||||
[
|
||||
'profile' => $profile,
|
||||
'items' => $data['items'],
|
||||
'permalink' => $data['permalink']
|
||||
]
|
||||
)
|
||||
->withHeaders($data['headers']);
|
||||
}
|
||||
$pid = AccountService::usernameToId($user);
|
||||
|
||||
public function meRedirect()
|
||||
{
|
||||
abort_if(!Auth::check(), 404);
|
||||
return redirect(Auth::user()->url());
|
||||
}
|
||||
abort_if(! $pid, 404);
|
||||
|
||||
public function embed(Request $request, $username)
|
||||
{
|
||||
$res = view('profile.embed-removed');
|
||||
$profile = AccountService::get($pid, true);
|
||||
|
||||
if(!config('instance.embed.profile')) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
abort_if(! $profile || $profile['locked'] || ! $profile['local'], 404);
|
||||
|
||||
if(strlen($username) > 15 || strlen($username) < 2) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:'.$profile['id'], 3600, function () use ($profile) {
|
||||
$uid = User::whereProfileId($profile['id'])->first();
|
||||
if (! $uid) {
|
||||
return true;
|
||||
}
|
||||
$exists = AccountInterstitial::whereUserId($uid->id)->where('is_spam', 1)->count();
|
||||
if ($exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$profile = Profile::whereUsername($username)
|
||||
->whereIsPrivate(false)
|
||||
->whereNull('status')
|
||||
->whereNull('domain')
|
||||
->first();
|
||||
return false;
|
||||
});
|
||||
|
||||
if(!$profile) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
abort_if($aiCheck, 404);
|
||||
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:' . $profile->id, 86400, function() use($profile) {
|
||||
$exists = AccountInterstitial::whereUserId($profile->user_id)->where('is_spam', 1)->count();
|
||||
if($exists) {
|
||||
return true;
|
||||
}
|
||||
$enabled = Cache::remember('profile:atom:enabled:'.$profile['id'], 84600, function () use ($profile) {
|
||||
$uid = User::whereProfileId($profile['id'])->first();
|
||||
if (! $uid) {
|
||||
return false;
|
||||
}
|
||||
$settings = UserSetting::whereUserId($uid->id)->first();
|
||||
if (! $settings) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
return $settings->show_atom;
|
||||
});
|
||||
|
||||
if($aiCheck) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
abort_if(! $enabled, 404);
|
||||
|
||||
if(AccountService::canEmbed($profile->user_id) == false) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
$data = Cache::remember('pf:atom:user-feed:by-id:'.$profile['id'], 14400, function () use ($pid, $profile) {
|
||||
$items = Status::whereProfileId($pid)
|
||||
->whereScope('public')
|
||||
->whereIn('type', ['photo', 'photo:album'])
|
||||
->orderByDesc('id')
|
||||
->take(10)
|
||||
->get()
|
||||
->map(function ($status) {
|
||||
return StatusService::get($status->id, true);
|
||||
})
|
||||
->filter(function ($status) {
|
||||
return $status &&
|
||||
isset($status['account']) &&
|
||||
isset($status['media_attachments']) &&
|
||||
count($status['media_attachments']);
|
||||
})
|
||||
->values();
|
||||
$permalink = config('app.url')."/users/{$profile['username']}.atom";
|
||||
$headers = ['Content-Type' => 'application/atom+xml'];
|
||||
|
||||
$profile = AccountService::get($profile->id);
|
||||
$res = view('profile.embed', compact('profile'));
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
if ($items && $items->count()) {
|
||||
$headers['Last-Modified'] = now()->parse($items->first()['created_at'])->toRfc7231String();
|
||||
}
|
||||
|
||||
public function stories(Request $request, $username)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||
$pid = $profile->id;
|
||||
$authed = Auth::user()->profile_id;
|
||||
abort_if($pid != $authed && !FollowerService::follows($authed, $pid), 404);
|
||||
$exists = Story::whereProfileId($pid)
|
||||
->whereActive(true)
|
||||
->exists();
|
||||
abort_unless($exists, 404);
|
||||
return view('profile.story', compact('pid', 'profile'));
|
||||
}
|
||||
return compact('items', 'permalink', 'headers');
|
||||
});
|
||||
abort_if(! $data || ! isset($data['items']) || ! isset($data['permalink']), 404);
|
||||
|
||||
return response()
|
||||
->view('atom.user',
|
||||
[
|
||||
'profile' => $profile,
|
||||
'items' => $data['items'],
|
||||
'permalink' => $data['permalink'],
|
||||
]
|
||||
)
|
||||
->withHeaders($data['headers']);
|
||||
}
|
||||
|
||||
public function meRedirect()
|
||||
{
|
||||
abort_if(! Auth::check(), 404);
|
||||
|
||||
return redirect(Auth::user()->url());
|
||||
}
|
||||
|
||||
public function embed(Request $request, $username)
|
||||
{
|
||||
$res = view('profile.embed-removed');
|
||||
|
||||
if (! (bool) config_cache('instance.embed.profile')) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
if (strlen($username) > 15 || strlen($username) < 2) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
$profile = $this->getCachedUser($username);
|
||||
|
||||
if (! $profile || $profile->is_private) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:'.$profile->id, 3600, function () use ($profile) {
|
||||
$exists = AccountInterstitial::whereUserId($profile->user_id)->where('is_spam', 1)->count();
|
||||
if ($exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($aiCheck) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
if (AccountService::canEmbed($profile->user_id) == false) {
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
$profile = AccountService::get($profile->id);
|
||||
$res = view('profile.embed', compact('profile'));
|
||||
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
public function stories(Request $request, $username)
|
||||
{
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||
$pid = $profile->id;
|
||||
$authed = Auth::user()->profile_id;
|
||||
abort_if($pid != $authed && ! FollowerService::follows($authed, $pid), 404);
|
||||
$exists = Story::whereProfileId($pid)
|
||||
->whereActive(true)
|
||||
->exists();
|
||||
abort_unless($exists, 404);
|
||||
|
||||
return view('profile.story', compact('pid', 'profile'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileMigrationStoreRequest;
|
||||
use App\Jobs\ProfilePipeline\ProfileMigrationDeliverMoveActivityPipeline;
|
||||
use App\Jobs\ProfilePipeline\ProfileMigrationMoveFollowersPipeline;
|
||||
use App\Models\ProfileAlias;
|
||||
use App\Models\ProfileMigration;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\WebfingerService;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
|
||||
class ProfileMigrationController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
abort_if((bool) config_cache('federation.activitypub.enabled') === false, 404);
|
||||
if ((bool) config_cache('federation.migration') === false) {
|
||||
return redirect(route('help.account-migration'));
|
||||
}
|
||||
$hasExistingMigration = ProfileMigration::whereProfileId($request->user()->profile_id)
|
||||
->where('created_at', '>', now()->subDays(30))
|
||||
->exists();
|
||||
|
||||
return view('settings.migration.index', compact('hasExistingMigration'));
|
||||
}
|
||||
|
||||
public function store(ProfileMigrationStoreRequest $request)
|
||||
{
|
||||
abort_if((bool) config_cache('federation.activitypub.enabled') === false, 404);
|
||||
$acct = WebfingerService::rawGet($request->safe()->acct);
|
||||
if (! $acct) {
|
||||
return redirect()->back()->withErrors(['acct' => 'The new account you provided is not responding to our requests.']);
|
||||
}
|
||||
$newAccount = Helpers::profileFetch($acct);
|
||||
if (! $newAccount) {
|
||||
return redirect()->back()->withErrors(['acct' => 'An error occured, please try again later. Code: res-failed-account-fetch']);
|
||||
}
|
||||
$user = $request->user();
|
||||
ProfileAlias::updateOrCreate([
|
||||
'profile_id' => $user->profile_id,
|
||||
'acct' => $request->safe()->acct,
|
||||
'uri' => $acct,
|
||||
]);
|
||||
$migration = ProfileMigration::create([
|
||||
'profile_id' => $request->user()->profile_id,
|
||||
'acct' => $request->safe()->acct,
|
||||
'followers_count' => $request->user()->profile->followers_count,
|
||||
'target_profile_id' => $newAccount['id'],
|
||||
]);
|
||||
$user->profile->update([
|
||||
'moved_to_profile_id' => $newAccount->id,
|
||||
'indexable' => false,
|
||||
]);
|
||||
AccountService::del($user->profile_id);
|
||||
|
||||
Bus::batch([
|
||||
new ProfileMigrationDeliverMoveActivityPipeline($migration, $user->profile, $newAccount),
|
||||
new ProfileMigrationMoveFollowersPipeline($user->profile_id, $newAccount->id),
|
||||
])->onQueue('follow')->dispatch();
|
||||
|
||||
return redirect()->back()->with(['status' => 'Succesfully migrated account!']);
|
||||
}
|
||||
}
|
|
@ -2,22 +2,20 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\Account\RemoteAuthService;
|
||||
use App\Models\RemoteAuth;
|
||||
use App\Profile;
|
||||
use App\Instance;
|
||||
use App\User;
|
||||
use Purify;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use App\Util\Lexer\RestrictedNames;
|
||||
use App\Services\Account\RemoteAuthService;
|
||||
use App\Services\EmailService;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\User;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Util\Lexer\RestrictedNames;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use InvalidArgumentException;
|
||||
use Purify;
|
||||
|
||||
class RemoteAuthController extends Controller
|
||||
{
|
||||
|
@ -30,9 +28,10 @@ class RemoteAuthController extends Controller
|
|||
config('remote-auth.mastodon.ignore_closed_state') &&
|
||||
config('remote-auth.mastodon.enabled')
|
||||
), 404);
|
||||
if($request->user()) {
|
||||
if ($request->user()) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
return view('auth.remote.start');
|
||||
}
|
||||
|
||||
|
@ -51,25 +50,27 @@ class RemoteAuthController extends Controller
|
|||
config('remote-auth.mastodon.enabled')
|
||||
), 404);
|
||||
|
||||
if(config('remote-auth.mastodon.domains.only_custom')) {
|
||||
if (config('remote-auth.mastodon.domains.only_custom')) {
|
||||
$res = config('remote-auth.mastodon.domains.custom');
|
||||
if(!$res || !strlen($res)) {
|
||||
if (! $res || ! strlen($res)) {
|
||||
return [];
|
||||
}
|
||||
$res = explode(',', $res);
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
if( config('remote-auth.mastodon.domains.custom') &&
|
||||
!config('remote-auth.mastodon.domains.only_default') &&
|
||||
if (config('remote-auth.mastodon.domains.custom') &&
|
||||
! config('remote-auth.mastodon.domains.only_default') &&
|
||||
strlen(config('remote-auth.mastodon.domains.custom')) > 3 &&
|
||||
strpos(config('remote-auth.mastodon.domains.custom'), '.') > -1
|
||||
) {
|
||||
$res = config('remote-auth.mastodon.domains.custom');
|
||||
if(!$res || !strlen($res)) {
|
||||
if (! $res || ! strlen($res)) {
|
||||
return [];
|
||||
}
|
||||
$res = explode(',', $res);
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
|
@ -93,57 +94,62 @@ class RemoteAuthController extends Controller
|
|||
|
||||
$domain = $request->input('domain');
|
||||
|
||||
if(str_starts_with(strtolower($domain), 'http')) {
|
||||
if (str_starts_with(strtolower($domain), 'http')) {
|
||||
$res = [
|
||||
'domain' => $domain,
|
||||
'ready' => false,
|
||||
'action' => 'incompatible_domain'
|
||||
'action' => 'incompatible_domain',
|
||||
];
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
$validateInstance = Helpers::validateUrl('https://' . $domain . '/?block-check=' . time());
|
||||
$validateInstance = Helpers::validateUrl('https://'.$domain.'/?block-check='.time());
|
||||
|
||||
if(!$validateInstance) {
|
||||
$res = [
|
||||
if (! $validateInstance) {
|
||||
$res = [
|
||||
'domain' => $domain,
|
||||
'ready' => false,
|
||||
'action' => 'blocked_domain'
|
||||
'action' => 'blocked_domain',
|
||||
];
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
$compatible = RemoteAuthService::isDomainCompatible($domain);
|
||||
|
||||
if(!$compatible) {
|
||||
if (! $compatible) {
|
||||
$res = [
|
||||
'domain' => $domain,
|
||||
'ready' => false,
|
||||
'action' => 'incompatible_domain'
|
||||
'action' => 'incompatible_domain',
|
||||
];
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
|
||||
if(config('remote-auth.mastodon.domains.only_default')) {
|
||||
if (config('remote-auth.mastodon.domains.only_default')) {
|
||||
$defaultDomains = explode(',', config('remote-auth.mastodon.domains.default'));
|
||||
if(!in_array($domain, $defaultDomains)) {
|
||||
if (! in_array($domain, $defaultDomains)) {
|
||||
$res = [
|
||||
'domain' => $domain,
|
||||
'ready' => false,
|
||||
'action' => 'incompatible_domain'
|
||||
'action' => 'incompatible_domain',
|
||||
];
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
}
|
||||
|
||||
if(config('remote-auth.mastodon.domains.only_custom') && config('remote-auth.mastodon.domains.custom')) {
|
||||
if (config('remote-auth.mastodon.domains.only_custom') && config('remote-auth.mastodon.domains.custom')) {
|
||||
$customDomains = explode(',', config('remote-auth.mastodon.domains.custom'));
|
||||
if(!in_array($domain, $customDomains)) {
|
||||
if (! in_array($domain, $customDomains)) {
|
||||
$res = [
|
||||
'domain' => $domain,
|
||||
'ready' => false,
|
||||
'action' => 'incompatible_domain'
|
||||
'action' => 'incompatible_domain',
|
||||
];
|
||||
|
||||
return response()->json($res);
|
||||
}
|
||||
}
|
||||
|
@ -163,13 +169,13 @@ class RemoteAuthController extends Controller
|
|||
'state' => $state,
|
||||
]);
|
||||
|
||||
$request->session()->put('oauth_redirect_to', 'https://' . $domain . '/oauth/authorize?' . $query);
|
||||
$request->session()->put('oauth_redirect_to', 'https://'.$domain.'/oauth/authorize?'.$query);
|
||||
|
||||
$dsh = Str::random(17);
|
||||
$res = [
|
||||
'domain' => $domain,
|
||||
'ready' => true,
|
||||
'dsh' => $dsh
|
||||
'dsh' => $dsh,
|
||||
];
|
||||
|
||||
return response()->json($res);
|
||||
|
@ -185,7 +191,7 @@ class RemoteAuthController extends Controller
|
|||
config('remote-auth.mastodon.enabled')
|
||||
), 404);
|
||||
|
||||
if(!$request->filled('d') || !$request->filled('dsh') || !$request->session()->exists('oauth_redirect_to')) {
|
||||
if (! $request->filled('d') || ! $request->filled('dsh') || ! $request->session()->exists('oauth_redirect_to')) {
|
||||
return redirect('/login');
|
||||
}
|
||||
|
||||
|
@ -204,7 +210,7 @@ class RemoteAuthController extends Controller
|
|||
|
||||
$domain = $request->session()->get('oauth_domain');
|
||||
|
||||
if($request->filled('code')) {
|
||||
if ($request->filled('code')) {
|
||||
$code = $request->input('code');
|
||||
$state = $request->session()->pull('state');
|
||||
|
||||
|
@ -216,12 +222,14 @@ class RemoteAuthController extends Controller
|
|||
|
||||
$res = RemoteAuthService::getToken($domain, $code);
|
||||
|
||||
if(!$res || !isset($res['access_token'])) {
|
||||
if (! $res || ! isset($res['access_token'])) {
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect('/login');
|
||||
}
|
||||
|
||||
$request->session()->put('oauth_remote_session_token', $res['access_token']);
|
||||
|
||||
return redirect('/auth/mastodon/getting-started');
|
||||
}
|
||||
|
||||
|
@ -237,9 +245,10 @@ class RemoteAuthController extends Controller
|
|||
config('remote-auth.mastodon.ignore_closed_state') &&
|
||||
config('remote-auth.mastodon.enabled')
|
||||
), 404);
|
||||
if($request->user()) {
|
||||
if ($request->user()) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
return view('auth.remote.onboarding');
|
||||
}
|
||||
|
||||
|
@ -261,36 +270,36 @@ class RemoteAuthController extends Controller
|
|||
|
||||
$res = RemoteAuthService::getVerifyCredentials($domain, $token);
|
||||
|
||||
abort_if(!$res || !isset($res['acct']), 403, 'Invalid credentials');
|
||||
abort_if(! $res || ! isset($res['acct']), 403, 'Invalid credentials');
|
||||
|
||||
$webfinger = strtolower('@' . $res['acct'] . '@' . $domain);
|
||||
$webfinger = strtolower('@'.$res['acct'].'@'.$domain);
|
||||
$request->session()->put('oauth_masto_webfinger', $webfinger);
|
||||
|
||||
if(config('remote-auth.mastodon.max_uses.enabled')) {
|
||||
if (config('remote-auth.mastodon.max_uses.enabled')) {
|
||||
$limit = config('remote-auth.mastodon.max_uses.limit');
|
||||
$uses = RemoteAuthService::lookupWebfingerUses($webfinger);
|
||||
if($uses >= $limit) {
|
||||
if ($uses >= $limit) {
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'msg' => 'Success!',
|
||||
'action' => 'max_uses_reached'
|
||||
'action' => 'max_uses_reached',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$exists = RemoteAuth::whereDomain($domain)->where('webfinger', $webfinger)->whereNotNull('user_id')->first();
|
||||
if($exists && $exists->user_id) {
|
||||
if ($exists && $exists->user_id) {
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'msg' => 'Success!',
|
||||
'action' => 'redirect_existing_user'
|
||||
'action' => 'redirect_existing_user',
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'msg' => 'Success!',
|
||||
'action' => 'onboard'
|
||||
'action' => 'onboard',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -311,7 +320,7 @@ class RemoteAuthController extends Controller
|
|||
$token = $request->session()->get('oauth_remote_session_token');
|
||||
|
||||
$res = RemoteAuthService::getVerifyCredentials($domain, $token);
|
||||
$res['_webfinger'] = strtolower('@' . $res['acct'] . '@' . $domain);
|
||||
$res['_webfinger'] = strtolower('@'.$res['acct'].'@'.$domain);
|
||||
$res['_domain'] = strtolower($domain);
|
||||
$request->session()->put('oauth_remasto_id', $res['id']);
|
||||
|
||||
|
@ -324,7 +333,7 @@ class RemoteAuthController extends Controller
|
|||
'bearer_token' => $token,
|
||||
'verify_credentials' => $res,
|
||||
'last_verify_credentials_at' => now(),
|
||||
'last_successful_login_at' => now()
|
||||
'last_successful_login_at' => now(),
|
||||
]);
|
||||
|
||||
$request->session()->put('oauth_masto_raid', $ra->id);
|
||||
|
@ -355,24 +364,24 @@ class RemoteAuthController extends Controller
|
|||
$underscore = substr_count($value, '_');
|
||||
$period = substr_count($value, '.');
|
||||
|
||||
if(ends_with($value, ['.php', '.js', '.css'])) {
|
||||
if (ends_with($value, ['.php', '.js', '.css'])) {
|
||||
return $fail('Username is invalid.');
|
||||
}
|
||||
|
||||
if(($dash + $underscore + $period) > 1) {
|
||||
if (($dash + $underscore + $period) > 1) {
|
||||
return $fail('Username is invalid. Can only contain one dash (-), period (.) or underscore (_).');
|
||||
}
|
||||
|
||||
if (!ctype_alnum($value[0])) {
|
||||
if (! ctype_alnum($value[0])) {
|
||||
return $fail('Username is invalid. Must start with a letter or number.');
|
||||
}
|
||||
|
||||
if (!ctype_alnum($value[strlen($value) - 1])) {
|
||||
if (! ctype_alnum($value[strlen($value) - 1])) {
|
||||
return $fail('Username is invalid. Must end with a letter or number.');
|
||||
}
|
||||
|
||||
$val = str_replace(['_', '.', '-'], '', $value);
|
||||
if(!ctype_alnum($val)) {
|
||||
if (! ctype_alnum($val)) {
|
||||
return $fail('Username is invalid. Username must be alpha-numeric and may contain dashes (-), periods (.) and underscores (_).');
|
||||
}
|
||||
|
||||
|
@ -380,8 +389,8 @@ class RemoteAuthController extends Controller
|
|||
if (in_array(strtolower($value), array_map('strtolower', $restricted))) {
|
||||
return $fail('Username cannot be used.');
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
]);
|
||||
$username = strtolower($request->input('username'));
|
||||
|
||||
|
@ -390,7 +399,7 @@ class RemoteAuthController extends Controller
|
|||
return response()->json([
|
||||
'code' => 200,
|
||||
'username' => $username,
|
||||
'exists' => $exists
|
||||
'exists' => $exists,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -411,7 +420,7 @@ class RemoteAuthController extends Controller
|
|||
'email' => [
|
||||
'required',
|
||||
'email:strict,filter_unicode,dns,spoof',
|
||||
]
|
||||
],
|
||||
]);
|
||||
|
||||
$email = $request->input('email');
|
||||
|
@ -422,7 +431,7 @@ class RemoteAuthController extends Controller
|
|||
'code' => 200,
|
||||
'email' => $email,
|
||||
'exists' => $exists,
|
||||
'banned' => $banned
|
||||
'banned' => $banned,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -445,18 +454,18 @@ class RemoteAuthController extends Controller
|
|||
|
||||
$res = RemoteAuthService::getFollowing($domain, $token, $id);
|
||||
|
||||
if(!$res) {
|
||||
if (! $res) {
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'following' => []
|
||||
'following' => [],
|
||||
]);
|
||||
}
|
||||
|
||||
$res = collect($res)->filter(fn($acct) => Helpers::validateUrl($acct['url']))->values()->toArray();
|
||||
$res = collect($res)->filter(fn ($acct) => Helpers::validateUrl($acct['url']))->values()->toArray();
|
||||
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'following' => $res
|
||||
'following' => $res,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -487,24 +496,24 @@ class RemoteAuthController extends Controller
|
|||
$underscore = substr_count($value, '_');
|
||||
$period = substr_count($value, '.');
|
||||
|
||||
if(ends_with($value, ['.php', '.js', '.css'])) {
|
||||
if (ends_with($value, ['.php', '.js', '.css'])) {
|
||||
return $fail('Username is invalid.');
|
||||
}
|
||||
|
||||
if(($dash + $underscore + $period) > 1) {
|
||||
if (($dash + $underscore + $period) > 1) {
|
||||
return $fail('Username is invalid. Can only contain one dash (-), period (.) or underscore (_).');
|
||||
}
|
||||
|
||||
if (!ctype_alnum($value[0])) {
|
||||
if (! ctype_alnum($value[0])) {
|
||||
return $fail('Username is invalid. Must start with a letter or number.');
|
||||
}
|
||||
|
||||
if (!ctype_alnum($value[strlen($value) - 1])) {
|
||||
if (! ctype_alnum($value[strlen($value) - 1])) {
|
||||
return $fail('Username is invalid. Must end with a letter or number.');
|
||||
}
|
||||
|
||||
$val = str_replace(['_', '.', '-'], '', $value);
|
||||
if(!ctype_alnum($val)) {
|
||||
if (! ctype_alnum($val)) {
|
||||
return $fail('Username is invalid. Username must be alpha-numeric and may contain dashes (-), periods (.) and underscores (_).');
|
||||
}
|
||||
|
||||
|
@ -512,10 +521,10 @@ class RemoteAuthController extends Controller
|
|||
if (in_array(strtolower($value), array_map('strtolower', $restricted))) {
|
||||
return $fail('Username cannot be used.');
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
'password' => 'required|string|min:8|confirmed',
|
||||
'name' => 'nullable|max:30'
|
||||
'name' => 'nullable|max:30',
|
||||
]);
|
||||
|
||||
$email = $request->input('email');
|
||||
|
@ -527,7 +536,7 @@ class RemoteAuthController extends Controller
|
|||
'name' => $name,
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'email' => $email
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
$raid = $request->session()->pull('oauth_masto_raid');
|
||||
|
@ -541,7 +550,7 @@ class RemoteAuthController extends Controller
|
|||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Success',
|
||||
'token' => $token
|
||||
'token' => $token,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -585,7 +594,7 @@ class RemoteAuthController extends Controller
|
|||
abort_unless($request->session()->exists('oauth_remasto_id'), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'account' => 'required|url'
|
||||
'account' => 'required|url',
|
||||
]);
|
||||
|
||||
$account = $request->input('account');
|
||||
|
@ -594,10 +603,10 @@ class RemoteAuthController extends Controller
|
|||
$host = strtolower(config('pixelfed.domain.app'));
|
||||
$domain = strtolower(parse_url($account, PHP_URL_HOST));
|
||||
|
||||
if($domain == $host) {
|
||||
if ($domain == $host) {
|
||||
$username = Str::of($account)->explode('/')->last();
|
||||
$user = User::where('username', $username)->first();
|
||||
if($user) {
|
||||
if ($user) {
|
||||
return ['id' => (string) $user->profile_id];
|
||||
} else {
|
||||
return [];
|
||||
|
@ -605,7 +614,7 @@ class RemoteAuthController extends Controller
|
|||
} else {
|
||||
try {
|
||||
$profile = Helpers::profileFetch($account);
|
||||
if($profile) {
|
||||
if ($profile) {
|
||||
return ['id' => (string) $profile->id];
|
||||
} else {
|
||||
return [];
|
||||
|
@ -635,13 +644,13 @@ class RemoteAuthController extends Controller
|
|||
$user = $request->user();
|
||||
$profile = $user->profile;
|
||||
|
||||
abort_if(!$profile->avatar, 404, 'Missing avatar');
|
||||
abort_if(! $profile->avatar, 404, 'Missing avatar');
|
||||
|
||||
$avatar = $profile->avatar;
|
||||
$avatar->remote_url = $request->input('avatar_url');
|
||||
$avatar->save();
|
||||
|
||||
MediaStorageService::avatar($avatar, config_cache('pixelfed.cloud_storage') == false);
|
||||
MediaStorageService::avatar($avatar, (bool) config_cache('pixelfed.cloud_storage') == false);
|
||||
|
||||
return [200];
|
||||
}
|
||||
|
@ -657,7 +666,7 @@ class RemoteAuthController extends Controller
|
|||
), 404);
|
||||
abort_unless($request->user(), 404);
|
||||
|
||||
$currentWebfinger = '@' . $request->user()->username . '@' . config('pixelfed.domain.app');
|
||||
$currentWebfinger = '@'.$request->user()->username.'@'.config('pixelfed.domain.app');
|
||||
$ra = RemoteAuth::where('user_id', $request->user()->id)->firstOrFail();
|
||||
RemoteAuthService::submitToBeagle(
|
||||
$ra->webfinger,
|
||||
|
@ -691,19 +700,20 @@ class RemoteAuthController extends Controller
|
|||
$user = User::findOrFail($ra->user_id);
|
||||
abort_if($user->is_admin || $user->status != null, 422, 'Invalid auth action');
|
||||
Auth::loginUsingId($ra->user_id);
|
||||
|
||||
return [200];
|
||||
}
|
||||
|
||||
protected function createUser($data)
|
||||
{
|
||||
event(new Registered($user = User::create([
|
||||
'name' => Purify::clean($data['name']),
|
||||
'name' => Purify::clean($data['name']),
|
||||
'username' => $data['username'],
|
||||
'email' => $data['email'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
'email_verified_at' => config('remote-auth.mastodon.contraints.skip_email_verification') ? now() : null,
|
||||
'app_register_ip' => request()->ip(),
|
||||
'register_source' => 'mastodon'
|
||||
'register_source' => 'mastodon',
|
||||
])));
|
||||
|
||||
$this->guarder()->login($user);
|
||||
|
|
|
@ -2,368 +2,367 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Auth;
|
||||
use App\Hashtag;
|
||||
use App\Place;
|
||||
use App\Profile;
|
||||
use App\Services\WebfingerService;
|
||||
use App\Status;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Transformer\Api\{
|
||||
AccountTransformer,
|
||||
HashtagTransformer,
|
||||
StatusTransformer,
|
||||
};
|
||||
use App\Services\WebfingerService;
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
public $tokens = [];
|
||||
public $term = '';
|
||||
public $hash = '';
|
||||
public $cacheKey = 'api:search:tag:';
|
||||
public $tokens = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
public $term = '';
|
||||
|
||||
public function searchAPI(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:3|max:120',
|
||||
'src' => 'required|string|in:metro',
|
||||
'v' => 'required|integer|in:2',
|
||||
'scope' => 'required|in:all,hashtag,profile,remote,webfinger'
|
||||
]);
|
||||
public $hash = '';
|
||||
|
||||
$scope = $request->input('scope') ?? 'all';
|
||||
$this->term = e(urldecode($request->input('q')));
|
||||
$this->hash = hash('sha256', $this->term);
|
||||
public $cacheKey = 'api:search:tag:';
|
||||
|
||||
switch ($scope) {
|
||||
case 'all':
|
||||
$this->getHashtags();
|
||||
$this->getPosts();
|
||||
$this->getProfiles();
|
||||
// $this->getPlaces();
|
||||
break;
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
case 'hashtag':
|
||||
$this->getHashtags();
|
||||
break;
|
||||
public function searchAPI(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:3|max:120',
|
||||
'src' => 'required|string|in:metro',
|
||||
'v' => 'required|integer|in:2',
|
||||
'scope' => 'required|in:all,hashtag,profile,remote,webfinger',
|
||||
]);
|
||||
|
||||
case 'profile':
|
||||
$this->getProfiles();
|
||||
break;
|
||||
$scope = $request->input('scope') ?? 'all';
|
||||
$this->term = e(urldecode($request->input('q')));
|
||||
$this->hash = hash('sha256', $this->term);
|
||||
|
||||
case 'webfinger':
|
||||
$this->webfingerSearch();
|
||||
break;
|
||||
switch ($scope) {
|
||||
case 'all':
|
||||
$this->getHashtags();
|
||||
$this->getPosts();
|
||||
$this->getProfiles();
|
||||
// $this->getPlaces();
|
||||
break;
|
||||
|
||||
case 'remote':
|
||||
$this->remoteLookupSearch();
|
||||
break;
|
||||
case 'hashtag':
|
||||
$this->getHashtags();
|
||||
break;
|
||||
|
||||
case 'place':
|
||||
$this->getPlaces();
|
||||
break;
|
||||
case 'profile':
|
||||
$this->getProfiles();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case 'webfinger':
|
||||
$this->webfingerSearch();
|
||||
break;
|
||||
|
||||
return response()->json($this->tokens, 200, [], JSON_PRETTY_PRINT);
|
||||
}
|
||||
case 'remote':
|
||||
$this->remoteLookupSearch();
|
||||
break;
|
||||
|
||||
protected function getPosts()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$hash = hash('sha256', $tag);
|
||||
if( Helpers::validateUrl($tag) != false &&
|
||||
Helpers::validateLocalUrl($tag) != true &&
|
||||
config_cache('federation.activitypub.enabled') == true &&
|
||||
config('federation.activitypub.remoteFollow') == true
|
||||
) {
|
||||
$remote = Helpers::fetchFromUrl($tag);
|
||||
if( isset($remote['type']) &&
|
||||
$remote['type'] == 'Note') {
|
||||
$item = Helpers::statusFetch($tag);
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => $item->url(),
|
||||
'type' => 'status',
|
||||
'value' => "by {$item->profile->username} <span class='float-right'>{$item->created_at->diffForHumans(null, true, true)}</span>",
|
||||
'tokens' => [$item->caption],
|
||||
'name' => $item->caption,
|
||||
'thumb' => $item->thumb(),
|
||||
]];
|
||||
}
|
||||
} else {
|
||||
$posts = Status::select('id', 'profile_id', 'caption', 'created_at')
|
||||
->whereHas('media')
|
||||
->whereNull('in_reply_to_id')
|
||||
->whereNull('reblog_of_id')
|
||||
->whereProfileId(Auth::user()->profile_id)
|
||||
->where('caption', 'like', '%'.$tag.'%')
|
||||
->latest()
|
||||
->limit(10)
|
||||
->get();
|
||||
case 'place':
|
||||
$this->getPlaces();
|
||||
break;
|
||||
|
||||
if($posts->count() > 0) {
|
||||
$posts = $posts->map(function($item, $key) {
|
||||
return [
|
||||
'count' => 0,
|
||||
'url' => $item->url(),
|
||||
'type' => 'status',
|
||||
'value' => "by {$item->profile->username} <span class='float-right'>{$item->created_at->diffForHumans(null, true, true)}</span>",
|
||||
'tokens' => [$item->caption],
|
||||
'name' => $item->caption,
|
||||
'thumb' => $item->thumb(),
|
||||
'filter' => $item->firstMedia()->filter_class
|
||||
];
|
||||
});
|
||||
$this->tokens['posts'] = $posts;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
protected function getHashtags()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$key = $this->cacheKey . 'hashtags:' . $this->hash;
|
||||
$ttl = now()->addMinutes(1);
|
||||
$tokens = Cache::remember($key, $ttl, function() use($tag) {
|
||||
$htag = Str::startsWith($tag, '#') == true ? mb_substr($tag, 1) : $tag;
|
||||
$hashtags = Hashtag::select('id', 'name', 'slug')
|
||||
->where('slug', 'like', '%'.$htag.'%')
|
||||
->whereHas('posts')
|
||||
->limit(20)
|
||||
->get();
|
||||
if($hashtags->count() > 0) {
|
||||
$tags = $hashtags->map(function ($item, $key) {
|
||||
return [
|
||||
'count' => $item->posts()->count(),
|
||||
'url' => $item->url(),
|
||||
'type' => 'hashtag',
|
||||
'value' => $item->name,
|
||||
'tokens' => '',
|
||||
'name' => null,
|
||||
];
|
||||
});
|
||||
return $tags;
|
||||
}
|
||||
});
|
||||
$this->tokens['hashtags'] = $tokens;
|
||||
}
|
||||
return response()->json($this->tokens, 200, [], JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
protected function getPlaces()
|
||||
{
|
||||
$tag = $this->term;
|
||||
// $key = $this->cacheKey . 'places:' . $this->hash;
|
||||
// $ttl = now()->addHours(12);
|
||||
// $tokens = Cache::remember($key, $ttl, function() use($tag) {
|
||||
$htag = Str::contains($tag, ',') == true ? explode(',', $tag) : [$tag];
|
||||
$hashtags = Place::select('id', 'name', 'slug', 'country')
|
||||
->where('name', 'like', '%'.$htag[0].'%')
|
||||
->paginate(20);
|
||||
$tags = [];
|
||||
if($hashtags->count() > 0) {
|
||||
$tags = $hashtags->map(function ($item, $key) {
|
||||
return [
|
||||
'count' => null,
|
||||
'url' => $item->url(),
|
||||
'type' => 'place',
|
||||
'value' => $item->name . ', ' . $item->country,
|
||||
'tokens' => '',
|
||||
'name' => null,
|
||||
'city' => $item->name,
|
||||
'country' => $item->country
|
||||
];
|
||||
});
|
||||
// return $tags;
|
||||
}
|
||||
// });
|
||||
$this->tokens['places'] = $tags;
|
||||
$this->tokens['placesPagination'] = [
|
||||
'total' => $hashtags->total(),
|
||||
'current_page' => $hashtags->currentPage(),
|
||||
'last_page' => $hashtags->lastPage()
|
||||
];
|
||||
}
|
||||
protected function getPosts()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$hash = hash('sha256', $tag);
|
||||
if (Helpers::validateUrl($tag) != false &&
|
||||
Helpers::validateLocalUrl($tag) != true &&
|
||||
(bool) config_cache('federation.activitypub.enabled') == true &&
|
||||
config('federation.activitypub.remoteFollow') == true
|
||||
) {
|
||||
$remote = Helpers::fetchFromUrl($tag);
|
||||
if (isset($remote['type']) &&
|
||||
in_array($remote['type'], ['Note', 'Question'])
|
||||
) {
|
||||
$item = Helpers::statusFetch($tag);
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => $item->url(),
|
||||
'type' => 'status',
|
||||
'value' => "by {$item->profile->username} <span class='float-right'>{$item->created_at->diffForHumans(null, true, true)}</span>",
|
||||
'tokens' => [$item->caption],
|
||||
'name' => $item->caption,
|
||||
'thumb' => $item->thumb(),
|
||||
]];
|
||||
}
|
||||
} else {
|
||||
$posts = Status::select('id', 'profile_id', 'caption', 'created_at')
|
||||
->whereHas('media')
|
||||
->whereNull('in_reply_to_id')
|
||||
->whereNull('reblog_of_id')
|
||||
->whereProfileId(Auth::user()->profile_id)
|
||||
->where('caption', 'like', '%'.$tag.'%')
|
||||
->latest()
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
protected function getProfiles()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$remoteKey = $this->cacheKey . 'profiles:remote:' . $this->hash;
|
||||
$key = $this->cacheKey . 'profiles:' . $this->hash;
|
||||
$remoteTtl = now()->addMinutes(15);
|
||||
$ttl = now()->addHours(2);
|
||||
if( Helpers::validateUrl($tag) != false &&
|
||||
Helpers::validateLocalUrl($tag) != true &&
|
||||
config_cache('federation.activitypub.enabled') == true &&
|
||||
config('federation.activitypub.remoteFollow') == true
|
||||
) {
|
||||
$remote = Helpers::fetchFromUrl($tag);
|
||||
if( isset($remote['type']) &&
|
||||
$remote['type'] == 'Person'
|
||||
) {
|
||||
$this->tokens['profiles'] = Cache::remember($remoteKey, $remoteTtl, function() use($tag) {
|
||||
$item = Helpers::profileFirstOrNew($tag);
|
||||
$tokens = [[
|
||||
'count' => 1,
|
||||
'url' => $item->url(),
|
||||
'type' => 'profile',
|
||||
'value' => $item->username,
|
||||
'tokens' => [$item->username],
|
||||
'name' => $item->name,
|
||||
'entity' => [
|
||||
'id' => (string) $item->id,
|
||||
'following' => $item->followedBy(Auth::user()->profile),
|
||||
'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id),
|
||||
'thumb' => $item->avatarUrl(),
|
||||
'local' => (bool) !$item->domain,
|
||||
'post_count' => $item->statuses()->count()
|
||||
]
|
||||
]];
|
||||
return $tokens;
|
||||
});
|
||||
}
|
||||
}
|
||||
if ($posts->count() > 0) {
|
||||
$posts = $posts->map(function ($item, $key) {
|
||||
return [
|
||||
'count' => 0,
|
||||
'url' => $item->url(),
|
||||
'type' => 'status',
|
||||
'value' => "by {$item->profile->username} <span class='float-right'>{$item->created_at->diffForHumans(null, true, true)}</span>",
|
||||
'tokens' => [$item->caption],
|
||||
'name' => $item->caption,
|
||||
'thumb' => $item->thumb(),
|
||||
'filter' => $item->firstMedia()->filter_class,
|
||||
];
|
||||
});
|
||||
$this->tokens['posts'] = $posts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
$this->tokens['profiles'] = Cache::remember($key, $ttl, function() use($tag) {
|
||||
if(Str::startsWith($tag, '@')) {
|
||||
$tag = substr($tag, 1);
|
||||
}
|
||||
$users = Profile::select('status', 'domain', 'username', 'name', 'id')
|
||||
->whereNull('status')
|
||||
->where('username', 'like', '%'.$tag.'%')
|
||||
->limit(20)
|
||||
->orderBy('domain')
|
||||
->get();
|
||||
protected function getHashtags()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$key = $this->cacheKey.'hashtags:'.$this->hash;
|
||||
$ttl = now()->addMinutes(1);
|
||||
$tokens = Cache::remember($key, $ttl, function () use ($tag) {
|
||||
$htag = Str::startsWith($tag, '#') == true ? mb_substr($tag, 1) : $tag;
|
||||
$hashtags = Hashtag::select('id', 'name', 'slug')
|
||||
->where('slug', 'like', '%'.$htag.'%')
|
||||
->whereHas('posts')
|
||||
->limit(20)
|
||||
->get();
|
||||
if ($hashtags->count() > 0) {
|
||||
$tags = $hashtags->map(function ($item, $key) {
|
||||
return [
|
||||
'count' => $item->posts()->count(),
|
||||
'url' => $item->url(),
|
||||
'type' => 'hashtag',
|
||||
'value' => $item->name,
|
||||
'tokens' => '',
|
||||
'name' => null,
|
||||
];
|
||||
});
|
||||
|
||||
if($users->count() > 0) {
|
||||
return $users->map(function ($item, $key) {
|
||||
return [
|
||||
'count' => 0,
|
||||
'url' => $item->url(),
|
||||
'type' => 'profile',
|
||||
'value' => $item->username,
|
||||
'tokens' => [$item->username],
|
||||
'name' => $item->name,
|
||||
'avatar' => $item->avatarUrl(),
|
||||
'id' => (string) $item->id,
|
||||
'entity' => [
|
||||
'id' => (string) $item->id,
|
||||
'following' => $item->followedBy(Auth::user()->profile),
|
||||
'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id),
|
||||
'thumb' => $item->avatarUrl(),
|
||||
'local' => (bool) !$item->domain,
|
||||
'post_count' => $item->statuses()->count()
|
||||
]
|
||||
];
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
});
|
||||
$this->tokens['hashtags'] = $tokens;
|
||||
}
|
||||
|
||||
public function results(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:1',
|
||||
]);
|
||||
protected function getPlaces()
|
||||
{
|
||||
$tag = $this->term;
|
||||
// $key = $this->cacheKey . 'places:' . $this->hash;
|
||||
// $ttl = now()->addHours(12);
|
||||
// $tokens = Cache::remember($key, $ttl, function() use($tag) {
|
||||
$htag = Str::contains($tag, ',') == true ? explode(',', $tag) : [$tag];
|
||||
$hashtags = Place::select('id', 'name', 'slug', 'country')
|
||||
->where('name', 'like', '%'.$htag[0].'%')
|
||||
->paginate(20);
|
||||
$tags = [];
|
||||
if ($hashtags->count() > 0) {
|
||||
$tags = $hashtags->map(function ($item, $key) {
|
||||
return [
|
||||
'count' => null,
|
||||
'url' => $item->url(),
|
||||
'type' => 'place',
|
||||
'value' => $item->name.', '.$item->country,
|
||||
'tokens' => '',
|
||||
'name' => null,
|
||||
'city' => $item->name,
|
||||
'country' => $item->country,
|
||||
];
|
||||
});
|
||||
// return $tags;
|
||||
}
|
||||
// });
|
||||
$this->tokens['places'] = $tags;
|
||||
$this->tokens['placesPagination'] = [
|
||||
'total' => $hashtags->total(),
|
||||
'current_page' => $hashtags->currentPage(),
|
||||
'last_page' => $hashtags->lastPage(),
|
||||
];
|
||||
}
|
||||
|
||||
return view('search.results');
|
||||
}
|
||||
protected function getProfiles()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$remoteKey = $this->cacheKey.'profiles:remote:'.$this->hash;
|
||||
$key = $this->cacheKey.'profiles:'.$this->hash;
|
||||
$remoteTtl = now()->addMinutes(15);
|
||||
$ttl = now()->addHours(2);
|
||||
if (Helpers::validateUrl($tag) != false &&
|
||||
Helpers::validateLocalUrl($tag) != true &&
|
||||
(bool) config_cache('federation.activitypub.enabled') == true &&
|
||||
config('federation.activitypub.remoteFollow') == true
|
||||
) {
|
||||
$remote = Helpers::fetchFromUrl($tag);
|
||||
if (isset($remote['type']) &&
|
||||
$remote['type'] == 'Person'
|
||||
) {
|
||||
$this->tokens['profiles'] = Cache::remember($remoteKey, $remoteTtl, function () use ($tag) {
|
||||
$item = Helpers::profileFirstOrNew($tag);
|
||||
$tokens = [[
|
||||
'count' => 1,
|
||||
'url' => $item->url(),
|
||||
'type' => 'profile',
|
||||
'value' => $item->username,
|
||||
'tokens' => [$item->username],
|
||||
'name' => $item->name,
|
||||
'entity' => [
|
||||
'id' => (string) $item->id,
|
||||
'following' => $item->followedBy(Auth::user()->profile),
|
||||
'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id),
|
||||
'thumb' => $item->avatarUrl(),
|
||||
'local' => (bool) ! $item->domain,
|
||||
'post_count' => $item->statuses()->count(),
|
||||
],
|
||||
]];
|
||||
|
||||
protected function webfingerSearch()
|
||||
{
|
||||
$wfs = WebfingerService::lookup($this->term);
|
||||
return $tokens;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$this->tokens['profiles'] = Cache::remember($key, $ttl, function () use ($tag) {
|
||||
if (Str::startsWith($tag, '@')) {
|
||||
$tag = substr($tag, 1);
|
||||
}
|
||||
$users = Profile::select('status', 'domain', 'username', 'name', 'id')
|
||||
->whereNull('status')
|
||||
->where('username', 'like', '%'.$tag.'%')
|
||||
->limit(20)
|
||||
->orderBy('domain')
|
||||
->get();
|
||||
|
||||
if(empty($wfs)) {
|
||||
return;
|
||||
}
|
||||
if ($users->count() > 0) {
|
||||
return $users->map(function ($item, $key) {
|
||||
return [
|
||||
'count' => 0,
|
||||
'url' => $item->url(),
|
||||
'type' => 'profile',
|
||||
'value' => $item->username,
|
||||
'tokens' => [$item->username],
|
||||
'name' => $item->name,
|
||||
'avatar' => $item->avatarUrl(),
|
||||
'id' => (string) $item->id,
|
||||
'entity' => [
|
||||
'id' => (string) $item->id,
|
||||
'following' => $item->followedBy(Auth::user()->profile),
|
||||
'follow_request' => $item->hasFollowRequestById(Auth::user()->profile_id),
|
||||
'thumb' => $item->avatarUrl(),
|
||||
'local' => (bool) ! $item->domain,
|
||||
'post_count' => $item->statuses()->count(),
|
||||
],
|
||||
];
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$this->tokens['profiles'] = [
|
||||
[
|
||||
'count' => 1,
|
||||
'url' => $wfs['url'],
|
||||
'type' => 'profile',
|
||||
'value' => $wfs['username'],
|
||||
'tokens' => [$wfs['username']],
|
||||
'name' => $wfs['display_name'],
|
||||
'entity' => [
|
||||
'id' => (string) $wfs['id'],
|
||||
'following' => null,
|
||||
'follow_request' => null,
|
||||
'thumb' => $wfs['avatar'],
|
||||
'local' => (bool) $wfs['local']
|
||||
]
|
||||
]
|
||||
];
|
||||
return;
|
||||
}
|
||||
public function results(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:1',
|
||||
]);
|
||||
|
||||
protected function remotePostLookup()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$hash = hash('sha256', $tag);
|
||||
$local = Helpers::validateLocalUrl($tag);
|
||||
$valid = Helpers::validateUrl($tag);
|
||||
return view('search.results');
|
||||
}
|
||||
|
||||
if($valid == false || $local == true) {
|
||||
return;
|
||||
}
|
||||
protected function webfingerSearch()
|
||||
{
|
||||
$wfs = WebfingerService::lookup($this->term);
|
||||
|
||||
if(Status::whereUri($tag)->whereLocal(false)->exists()) {
|
||||
$item = Status::whereUri($tag)->first();
|
||||
$media = $item->firstMedia();
|
||||
$url = null;
|
||||
if($media) {
|
||||
$url = $media->remote_url;
|
||||
}
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => "/i/web/post/_/$item->profile_id/$item->id",
|
||||
'type' => 'status',
|
||||
'username' => $item->profile->username,
|
||||
'caption' => $item->rendered ?? $item->caption,
|
||||
'thumb' => $url,
|
||||
'timestamp' => $item->created_at->diffForHumans()
|
||||
]];
|
||||
}
|
||||
if (empty($wfs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$remote = Helpers::fetchFromUrl($tag);
|
||||
$this->tokens['profiles'] = [
|
||||
[
|
||||
'count' => 1,
|
||||
'url' => $wfs['url'],
|
||||
'type' => 'profile',
|
||||
'value' => $wfs['username'],
|
||||
'tokens' => [$wfs['username']],
|
||||
'name' => $wfs['display_name'],
|
||||
'entity' => [
|
||||
'id' => (string) $wfs['id'],
|
||||
'following' => null,
|
||||
'follow_request' => null,
|
||||
'thumb' => $wfs['avatar'],
|
||||
'local' => (bool) $wfs['local'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
if(isset($remote['type']) && $remote['type'] == 'Note') {
|
||||
$item = Helpers::statusFetch($tag);
|
||||
$media = $item->firstMedia();
|
||||
$url = null;
|
||||
if($media) {
|
||||
$url = $media->remote_url;
|
||||
}
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => "/i/web/post/_/$item->profile_id/$item->id",
|
||||
'type' => 'status',
|
||||
'username' => $item->profile->username,
|
||||
'caption' => $item->rendered ?? $item->caption,
|
||||
'thumb' => $url,
|
||||
'timestamp' => $item->created_at->diffForHumans()
|
||||
]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function remoteLookupSearch()
|
||||
{
|
||||
if(!Helpers::validateUrl($this->term)) {
|
||||
return;
|
||||
}
|
||||
$this->getProfiles();
|
||||
$this->remotePostLookup();
|
||||
}
|
||||
protected function remotePostLookup()
|
||||
{
|
||||
$tag = $this->term;
|
||||
$hash = hash('sha256', $tag);
|
||||
$local = Helpers::validateLocalUrl($tag);
|
||||
$valid = Helpers::validateUrl($tag);
|
||||
|
||||
if ($valid == false || $local == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Status::whereUri($tag)->whereLocal(false)->exists()) {
|
||||
$item = Status::whereUri($tag)->first();
|
||||
$media = $item->firstMedia();
|
||||
$url = null;
|
||||
if ($media) {
|
||||
$url = $media->remote_url;
|
||||
}
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => "/i/web/post/_/$item->profile_id/$item->id",
|
||||
'type' => 'status',
|
||||
'username' => $item->profile->username,
|
||||
'caption' => $item->rendered ?? $item->caption,
|
||||
'thumb' => $url,
|
||||
'timestamp' => $item->created_at->diffForHumans(),
|
||||
]];
|
||||
}
|
||||
|
||||
$remote = Helpers::fetchFromUrl($tag);
|
||||
|
||||
if (isset($remote['type']) && $remote['type'] == 'Note') {
|
||||
$item = Helpers::statusFetch($tag);
|
||||
$media = $item->firstMedia();
|
||||
$url = null;
|
||||
if ($media) {
|
||||
$url = $media->remote_url;
|
||||
}
|
||||
$this->tokens['posts'] = [[
|
||||
'count' => 0,
|
||||
'url' => "/i/web/post/_/$item->profile_id/$item->id",
|
||||
'type' => 'status',
|
||||
'username' => $item->profile->username,
|
||||
'caption' => $item->rendered ?? $item->caption,
|
||||
'thumb' => $url,
|
||||
'timestamp' => $item->created_at->diffForHumans(),
|
||||
]];
|
||||
}
|
||||
}
|
||||
|
||||
protected function remoteLookupSearch()
|
||||
{
|
||||
if (! Helpers::validateUrl($this->term)) {
|
||||
return;
|
||||
}
|
||||
$this->getProfiles();
|
||||
$this->remotePostLookup();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,23 +2,17 @@
|
|||
|
||||
namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\AccountLog;
|
||||
use App\EmailVerification;
|
||||
use App\Instance;
|
||||
use App\Follower;
|
||||
use App\Media;
|
||||
use App\Profile;
|
||||
use App\User;
|
||||
use App\Services\RelationshipService;
|
||||
use App\UserFilter;
|
||||
use App\Util\Lexer\PrettyNumber;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Auth, Cache, DB;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\UserDomainBlock;
|
||||
|
||||
trait PrivacySettings
|
||||
{
|
||||
|
||||
public function privacy()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
@ -35,13 +29,13 @@ trait PrivacySettings
|
|||
$settings = $request->user()->settings;
|
||||
$profile = $request->user()->profile;
|
||||
$fields = [
|
||||
'is_private',
|
||||
'crawlable',
|
||||
'public_dm',
|
||||
'show_profile_follower_count',
|
||||
'show_profile_following_count',
|
||||
'indexable',
|
||||
'show_atom',
|
||||
'is_private',
|
||||
'crawlable',
|
||||
'public_dm',
|
||||
'show_profile_follower_count',
|
||||
'show_profile_following_count',
|
||||
'indexable',
|
||||
'show_atom',
|
||||
];
|
||||
|
||||
$profile->indexable = $request->input('indexable') == 'on';
|
||||
|
@ -67,7 +61,7 @@ trait PrivacySettings
|
|||
} else {
|
||||
$settings->{$field} = true;
|
||||
}
|
||||
} elseif ($field == 'public_dm') {
|
||||
} elseif ($field == 'public_dm') {
|
||||
if ($form == 'on') {
|
||||
$settings->{$field} = true;
|
||||
} else {
|
||||
|
@ -84,29 +78,36 @@ trait PrivacySettings
|
|||
}
|
||||
$settings->save();
|
||||
}
|
||||
Cache::forget('profile:settings:' . $profile->id);
|
||||
Cache::forget('user:account:id:' . $profile->user_id);
|
||||
Cache::forget('profile:follower_count:' . $profile->id);
|
||||
Cache::forget('profile:following_count:' . $profile->id);
|
||||
Cache::forget('profile:atom:enabled:' . $profile->id);
|
||||
Cache::forget('profile:embed:' . $profile->id);
|
||||
Cache::forget('pf:acct:settings:hidden-followers:' . $profile->id);
|
||||
Cache::forget('pf:acct:settings:hidden-following:' . $profile->id);
|
||||
$pid = $profile->id;
|
||||
Cache::forget('profile:settings:'.$pid);
|
||||
Cache::forget('user:account:id:'.$profile->user_id);
|
||||
Cache::forget('profile:follower_count:'.$pid);
|
||||
Cache::forget('profile:following_count:'.$pid);
|
||||
Cache::forget('profile:atom:enabled:'.$pid);
|
||||
Cache::forget('profile:embed:'.$pid);
|
||||
Cache::forget('pf:acct:settings:hidden-followers:'.$pid);
|
||||
Cache::forget('pf:acct:settings:hidden-following:'.$pid);
|
||||
Cache::forget('pf:acct-trans:hideFollowing:'.$pid);
|
||||
Cache::forget('pf:acct-trans:hideFollowers:'.$pid);
|
||||
Cache::forget('pfc:cached-user:wt:'.strtolower($profile->username));
|
||||
Cache::forget('pfc:cached-user:wot:'.strtolower($profile->username));
|
||||
|
||||
return redirect(route('settings.privacy'))->with('status', 'Settings successfully updated!');
|
||||
}
|
||||
|
||||
public function mutedUsers()
|
||||
{
|
||||
{
|
||||
$pid = Auth::user()->profile->id;
|
||||
$ids = (new UserFilter())->mutedUserIds($pid);
|
||||
$users = Profile::whereIn('id', $ids)->simplePaginate(15);
|
||||
|
||||
return view('settings.privacy.muted', compact('users'));
|
||||
}
|
||||
|
||||
public function mutedUsersUpdate(Request $request)
|
||||
{
|
||||
{
|
||||
$this->validate($request, [
|
||||
'profile_id' => 'required|integer|min:1'
|
||||
'profile_id' => 'required|integer|min:1',
|
||||
]);
|
||||
$fid = $request->input('profile_id');
|
||||
$pid = Auth::user()->profile->id;
|
||||
|
@ -118,6 +119,8 @@ trait PrivacySettings
|
|||
->firstOrFail();
|
||||
$filter->delete();
|
||||
});
|
||||
RelationshipService::refresh($pid, $fid);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
@ -126,14 +129,14 @@ trait PrivacySettings
|
|||
$pid = Auth::user()->profile->id;
|
||||
$ids = (new UserFilter())->blockedUserIds($pid);
|
||||
$users = Profile::whereIn('id', $ids)->simplePaginate(15);
|
||||
|
||||
return view('settings.privacy.blocked', compact('users'));
|
||||
}
|
||||
|
||||
|
||||
public function blockedUsersUpdate(Request $request)
|
||||
{
|
||||
{
|
||||
$this->validate($request, [
|
||||
'profile_id' => 'required|integer|min:1'
|
||||
'profile_id' => 'required|integer|min:1',
|
||||
]);
|
||||
$fid = $request->input('profile_id');
|
||||
$pid = Auth::user()->profile->id;
|
||||
|
@ -145,6 +148,8 @@ trait PrivacySettings
|
|||
->firstOrFail();
|
||||
$filter->delete();
|
||||
});
|
||||
RelationshipService::refresh($pid, $fid);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
@ -189,7 +194,7 @@ trait PrivacySettings
|
|||
$profile = Auth::user()->profile;
|
||||
$settings = Auth::user()->settings;
|
||||
|
||||
if($mode !== 'keep-all') {
|
||||
if ($mode !== 'keep-all') {
|
||||
switch ($mode) {
|
||||
case 'mutual-only':
|
||||
$following = $profile->following()->pluck('profiles.id');
|
||||
|
@ -204,9 +209,9 @@ trait PrivacySettings
|
|||
case 'remove-all':
|
||||
Follower::whereFollowingId($profile->id)->delete();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
# code...
|
||||
// code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -216,6 +221,7 @@ trait PrivacySettings
|
|||
$settings->save();
|
||||
$profile->save();
|
||||
Cache::forget('profiles:private');
|
||||
|
||||
return [200];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,166 +2,202 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Page;
|
||||
use App\Profile;
|
||||
use App\Services\FollowerService;
|
||||
use App\Status;
|
||||
use App\User;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Util\Localization\Localization;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App, Auth, Cache, View;
|
||||
use App\Util\Lexer\PrettyNumber;
|
||||
use App\{Follower, Page, Profile, Status, User, UserFilter};
|
||||
use App\Util\Localization\Localization;
|
||||
use App\Services\FollowerService;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use View;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
public function home(Request $request)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return $this->homeTimeline($request);
|
||||
} else {
|
||||
return $this->homeGuest();
|
||||
}
|
||||
}
|
||||
public function home(Request $request)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return $this->homeTimeline($request);
|
||||
} else {
|
||||
return $this->homeGuest();
|
||||
}
|
||||
}
|
||||
|
||||
public function homeGuest()
|
||||
{
|
||||
return view('site.index');
|
||||
}
|
||||
public function homeGuest()
|
||||
{
|
||||
return view('site.index');
|
||||
}
|
||||
|
||||
public function homeTimeline(Request $request)
|
||||
{
|
||||
if($request->has('force_old_ui')) {
|
||||
return view('timeline.home', ['layout' => 'feed']);
|
||||
}
|
||||
public function homeTimeline(Request $request)
|
||||
{
|
||||
if ($request->has('force_old_ui')) {
|
||||
return view('timeline.home', ['layout' => 'feed']);
|
||||
}
|
||||
|
||||
return redirect('/i/web');
|
||||
}
|
||||
return redirect('/i/web');
|
||||
}
|
||||
|
||||
public function changeLocale(Request $request, $locale)
|
||||
{
|
||||
// todo: add other locales after pushing new l10n strings
|
||||
$locales = Localization::languages();
|
||||
if(in_array($locale, $locales)) {
|
||||
if($request->user()) {
|
||||
$user = $request->user();
|
||||
$user->language = $locale;
|
||||
$user->save();
|
||||
}
|
||||
session()->put('locale', $locale);
|
||||
}
|
||||
public function changeLocale(Request $request, $locale)
|
||||
{
|
||||
// todo: add other locales after pushing new l10n strings
|
||||
$locales = Localization::languages();
|
||||
if (in_array($locale, $locales)) {
|
||||
if ($request->user()) {
|
||||
$user = $request->user();
|
||||
$user->language = $locale;
|
||||
$user->save();
|
||||
}
|
||||
session()->put('locale', $locale);
|
||||
}
|
||||
|
||||
return redirect(route('site.language'));
|
||||
}
|
||||
return redirect(route('site.language'));
|
||||
}
|
||||
|
||||
public function about()
|
||||
{
|
||||
return Cache::remember('site.about_v2', now()->addMinutes(15), function() {
|
||||
$user_count = number_format(User::count());
|
||||
$post_count = number_format(Status::count());
|
||||
$rules = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : null;
|
||||
return view('site.about', compact('rules', 'user_count', 'post_count'))->render();
|
||||
});
|
||||
}
|
||||
public function about()
|
||||
{
|
||||
return Cache::remember('site.about_v2', now()->addMinutes(15), function () {
|
||||
$user_count = number_format(User::count());
|
||||
$post_count = number_format(Status::count());
|
||||
$rules = config_cache('app.rules') ? json_decode(config_cache('app.rules'), true) : null;
|
||||
|
||||
public function language()
|
||||
{
|
||||
return view('site.language');
|
||||
}
|
||||
return view('site.about', compact('rules', 'user_count', 'post_count'))->render();
|
||||
});
|
||||
}
|
||||
|
||||
public function communityGuidelines(Request $request)
|
||||
{
|
||||
return Cache::remember('site:help:community-guidelines', now()->addDays(120), function() {
|
||||
$slug = '/site/kb/community-guidelines';
|
||||
$page = Page::whereSlug($slug)->whereActive(true)->first();
|
||||
return View::make('site.help.community-guidelines')->with(compact('page'))->render();
|
||||
});
|
||||
}
|
||||
public function language()
|
||||
{
|
||||
return view('site.language');
|
||||
}
|
||||
|
||||
public function privacy(Request $request)
|
||||
{
|
||||
$page = Cache::remember('site:privacy', now()->addDays(120), function() {
|
||||
$slug = '/site/privacy';
|
||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||
});
|
||||
return View::make('site.privacy')->with(compact('page'))->render();
|
||||
}
|
||||
public function communityGuidelines(Request $request)
|
||||
{
|
||||
return Cache::remember('site:help:community-guidelines', now()->addDays(120), function () {
|
||||
$slug = '/site/kb/community-guidelines';
|
||||
$page = Page::whereSlug($slug)->whereActive(true)->first();
|
||||
|
||||
public function terms(Request $request)
|
||||
{
|
||||
$page = Cache::remember('site:terms', now()->addDays(120), function() {
|
||||
$slug = '/site/terms';
|
||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||
});
|
||||
return View::make('site.terms')->with(compact('page'))->render();
|
||||
}
|
||||
return View::make('site.help.community-guidelines')->with(compact('page'))->render();
|
||||
});
|
||||
}
|
||||
|
||||
public function redirectUrl(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 404);
|
||||
$this->validate($request, [
|
||||
'url' => 'required|url'
|
||||
]);
|
||||
$url = request()->input('url');
|
||||
abort_if(Helpers::validateUrl($url) == false, 404);
|
||||
return view('site.redirect', compact('url'));
|
||||
}
|
||||
public function privacy(Request $request)
|
||||
{
|
||||
$page = Cache::remember('site:privacy', now()->addDays(120), function () {
|
||||
$slug = '/site/privacy';
|
||||
|
||||
public function followIntent(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'user' => 'string|min:1|max:15|exists:users,username',
|
||||
]);
|
||||
$profile = Profile::whereUsername($request->input('user'))->firstOrFail();
|
||||
$user = $request->user();
|
||||
abort_if($user && $profile->id == $user->profile_id, 404);
|
||||
$following = $user != null ? FollowerService::follows($user->profile_id, $profile->id) : false;
|
||||
return view('site.intents.follow', compact('profile', 'user', 'following'));
|
||||
}
|
||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||
});
|
||||
|
||||
public function legacyProfileRedirect(Request $request, $username)
|
||||
{
|
||||
$username = Str::contains($username, '@') ? '@' . $username : $username;
|
||||
if(str_contains($username, '@')) {
|
||||
$profile = Profile::whereUsername($username)
|
||||
->firstOrFail();
|
||||
return View::make('site.privacy')->with(compact('page'))->render();
|
||||
}
|
||||
|
||||
if($profile->domain == null) {
|
||||
$url = "/$profile->username";
|
||||
} else {
|
||||
$url = "/i/web/profile/_/{$profile->id}";
|
||||
}
|
||||
public function terms(Request $request)
|
||||
{
|
||||
$page = Cache::remember('site:terms', now()->addDays(120), function () {
|
||||
$slug = '/site/terms';
|
||||
|
||||
} else {
|
||||
$profile = Profile::whereUsername($username)
|
||||
->whereNull('domain')
|
||||
->firstOrFail();
|
||||
$url = "/$profile->username";
|
||||
}
|
||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||
});
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
return View::make('site.terms')->with(compact('page'))->render();
|
||||
}
|
||||
|
||||
public function legacyWebfingerRedirect(Request $request, $username, $domain)
|
||||
{
|
||||
$un = '@'.$username.'@'.$domain;
|
||||
$profile = Profile::whereUsername($un)
|
||||
->firstOrFail();
|
||||
public function redirectUrl(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 404);
|
||||
$this->validate($request, [
|
||||
'url' => 'required|url',
|
||||
]);
|
||||
$url = request()->input('url');
|
||||
abort_if(Helpers::validateUrl($url) == false, 404);
|
||||
|
||||
if($profile->domain == null) {
|
||||
$url = "/$profile->username";
|
||||
} else {
|
||||
$url = $request->user() ? "/i/web/profile/_/{$profile->id}" : $profile->url();
|
||||
}
|
||||
return view('site.redirect', compact('url'));
|
||||
}
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
public function followIntent(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'user' => 'string|min:1|max:15|exists:users,username',
|
||||
]);
|
||||
$profile = Profile::whereUsername($request->input('user'))->firstOrFail();
|
||||
$user = $request->user();
|
||||
abort_if($user && $profile->id == $user->profile_id, 404);
|
||||
$following = $user != null ? FollowerService::follows($user->profile_id, $profile->id) : false;
|
||||
|
||||
public function legalNotice(Request $request)
|
||||
{
|
||||
$page = Cache::remember('site:legal-notice', now()->addDays(120), function() {
|
||||
$slug = '/site/legal-notice';
|
||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||
});
|
||||
abort_if(!$page, 404);
|
||||
return View::make('site.legal-notice')->with(compact('page'))->render();
|
||||
}
|
||||
return view('site.intents.follow', compact('profile', 'user', 'following'));
|
||||
}
|
||||
|
||||
public function legacyProfileRedirect(Request $request, $username)
|
||||
{
|
||||
$username = Str::contains($username, '@') ? '@'.$username : $username;
|
||||
if (str_contains($username, '@')) {
|
||||
$profile = Profile::whereUsername($username)
|
||||
->firstOrFail();
|
||||
|
||||
if ($profile->domain == null) {
|
||||
$url = "/$profile->username";
|
||||
} else {
|
||||
$url = "/i/web/profile/_/{$profile->id}";
|
||||
}
|
||||
|
||||
} else {
|
||||
$profile = Profile::whereUsername($username)
|
||||
->whereNull('domain')
|
||||
->firstOrFail();
|
||||
$url = "/$profile->username";
|
||||
}
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
public function legacyWebfingerRedirect(Request $request, $username, $domain)
|
||||
{
|
||||
$un = '@'.$username.'@'.$domain;
|
||||
$profile = Profile::whereUsername($un)
|
||||
->firstOrFail();
|
||||
|
||||
if ($profile->domain == null) {
|
||||
$url = "/$profile->username";
|
||||
} else {
|
||||
$url = $request->user() ? "/i/web/profile/_/{$profile->id}" : $profile->url();
|
||||
}
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
public function legalNotice(Request $request)
|
||||
{
|
||||
$page = Cache::remember('site:legal-notice', now()->addDays(120), function () {
|
||||
$slug = '/site/legal-notice';
|
||||
|
||||
return Page::whereSlug($slug)->whereActive(true)->first();
|
||||
});
|
||||
abort_if(! $page, 404);
|
||||
|
||||
return View::make('site.legal-notice')->with(compact('page'))->render();
|
||||
}
|
||||
|
||||
public function curatedOnboarding(Request $request)
|
||||
{
|
||||
if ($request->user()) {
|
||||
return redirect('/i/web');
|
||||
}
|
||||
|
||||
$regOpen = (bool) config_cache('pixelfed.open_registration');
|
||||
$curOnboarding = (bool) config_cache('instance.curated_registration.enabled');
|
||||
$curOnlyClosed = (bool) config('instance.curated_registration.state.only_enabled_on_closed_reg');
|
||||
if ($regOpen) {
|
||||
if ($curOnlyClosed) {
|
||||
return redirect('/register');
|
||||
}
|
||||
} else {
|
||||
if (! $curOnboarding) {
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
|
||||
return view('auth.curated-register.index', ['step' => 1]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\Internal\SoftwareUpdateService;
|
||||
|
||||
class SoftwareUpdateController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
$this->middleware('admin');
|
||||
}
|
||||
|
||||
public function getSoftwareUpdateCheck(Request $request)
|
||||
{
|
||||
$res = SoftwareUpdateService::get();
|
||||
return $res;
|
||||
}
|
||||
}
|
|
@ -2,458 +2,486 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Jobs\ImageOptimizePipeline\ImageOptimize;
|
||||
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
||||
use App\Jobs\StatusPipeline\StatusDelete;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
use App\AccountInterstitial;
|
||||
use App\Jobs\SharePipeline\SharePipeline;
|
||||
use App\Jobs\SharePipeline\UndoSharePipeline;
|
||||
use App\AccountInterstitial;
|
||||
use App\Media;
|
||||
use App\Jobs\StatusPipeline\RemoteStatusDelete;
|
||||
use App\Jobs\StatusPipeline\StatusDelete;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\ReblogService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\StatusArchived;
|
||||
use App\StatusView;
|
||||
use App\Transformer\ActivityPub\StatusTransformer;
|
||||
use App\Transformer\ActivityPub\Verb\Note;
|
||||
use App\Transformer\ActivityPub\Verb\Question;
|
||||
use App\User;
|
||||
use Auth, DB, Cache;
|
||||
use App\Util\Media\License;
|
||||
use Auth;
|
||||
use Cache;
|
||||
use DB;
|
||||
use Illuminate\Http\Request;
|
||||
use League\Fractal;
|
||||
use App\Util\Media\Filter;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Services\HashidService;
|
||||
use App\Services\StatusService;
|
||||
use App\Util\Media\License;
|
||||
use App\Services\ReblogService;
|
||||
|
||||
class StatusController extends Controller
|
||||
{
|
||||
public function show(Request $request, $username, $id)
|
||||
{
|
||||
// redirect authed users to Metro 2.0
|
||||
if($request->user()) {
|
||||
// unless they force static view
|
||||
if(!$request->has('fs') || $request->input('fs') != '1') {
|
||||
return redirect('/i/web/post/' . $id);
|
||||
}
|
||||
}
|
||||
|
||||
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||
|
||||
if($user->status != null) {
|
||||
return ProfileController::accountCheck($user);
|
||||
}
|
||||
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->whereNull('reblog_of_id')
|
||||
->whereIn('scope', ['public','unlisted', 'private'])
|
||||
->findOrFail($id);
|
||||
|
||||
if($status->uri || $status->url) {
|
||||
$url = $status->uri ?? $status->url;
|
||||
if(ends_with($url, '/activity')) {
|
||||
$url = str_replace('/activity', '', $url);
|
||||
}
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
if($status->visibility == 'private' || $user->is_private) {
|
||||
if(!Auth::check()) {
|
||||
abort(404);
|
||||
}
|
||||
$pid = Auth::user()->profile;
|
||||
if($user->followedBy($pid) == false && $user->id !== $pid->id && Auth::user()->is_admin == false) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
if($status->type == 'archived') {
|
||||
if(Auth::user()->profile_id !== $status->profile_id) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
if($request->user() && $request->user()->profile_id != $status->profile_id) {
|
||||
StatusView::firstOrCreate([
|
||||
'status_id' => $status->id,
|
||||
'status_profile_id' => $status->profile_id,
|
||||
'profile_id' => $request->user()->profile_id
|
||||
]);
|
||||
}
|
||||
|
||||
if ($request->wantsJson() && config_cache('federation.activitypub.enabled')) {
|
||||
return $this->showActivityPub($request, $status);
|
||||
}
|
||||
|
||||
$template = $status->in_reply_to_id ? 'status.reply' : 'status.show';
|
||||
return view($template, compact('user', 'status'));
|
||||
}
|
||||
|
||||
public function shortcodeRedirect(Request $request, $id)
|
||||
{
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function showId(int $id)
|
||||
{
|
||||
abort(404);
|
||||
$status = Status::whereNull('reblog_of_id')
|
||||
->whereIn('scope', ['public', 'unlisted'])
|
||||
->findOrFail($id);
|
||||
return redirect($status->url());
|
||||
}
|
||||
|
||||
public function showEmbed(Request $request, $username, int $id)
|
||||
{
|
||||
if(!config('instance.embed.post')) {
|
||||
$res = view('status.embed-removed');
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
$profile = Profile::whereNull(['domain','status'])
|
||||
->whereIsPrivate(false)
|
||||
->whereUsername($username)
|
||||
->first();
|
||||
|
||||
if(!$profile) {
|
||||
$content = view('status.embed-removed');
|
||||
return response($content)->header('X-Frame-Options', 'ALLOWALL');
|
||||
}
|
||||
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:' . $profile->id, 86400, function() use($profile) {
|
||||
$exists = AccountInterstitial::whereUserId($profile->user_id)->where('is_spam', 1)->count();
|
||||
if($exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if($aiCheck) {
|
||||
$res = view('status.embed-removed');
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
$status = Status::whereProfileId($profile->id)
|
||||
->whereNull('uri')
|
||||
->whereScope('public')
|
||||
->whereIsNsfw(false)
|
||||
->whereIn('type', ['photo', 'video','photo:album'])
|
||||
->find($id);
|
||||
if(!$status) {
|
||||
$content = view('status.embed-removed');
|
||||
return response($content)->header('X-Frame-Options', 'ALLOWALL');
|
||||
}
|
||||
$showLikes = $request->filled('likes') && $request->likes == true;
|
||||
$showCaption = $request->filled('caption') && $request->caption !== false;
|
||||
$layout = $request->filled('layout') && $request->layout == 'compact' ? 'compact' : 'full';
|
||||
$content = view('status.embed', compact('status', 'showLikes', 'showCaption', 'layout'));
|
||||
return response($content)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
public function showObject(Request $request, $username, int $id)
|
||||
{
|
||||
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||
|
||||
if($user->status != null) {
|
||||
return ProfileController::accountCheck($user);
|
||||
}
|
||||
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->whereNotIn('visibility',['draft','direct'])
|
||||
->findOrFail($id);
|
||||
|
||||
abort_if($status->uri, 404);
|
||||
|
||||
if($status->visibility == 'private' || $user->is_private) {
|
||||
if(!Auth::check()) {
|
||||
abort(403);
|
||||
}
|
||||
$pid = Auth::user()->profile;
|
||||
if($user->followedBy($pid) == false && $user->id !== $pid->id) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->showActivityPub($request, $status);
|
||||
}
|
||||
|
||||
public function compose()
|
||||
{
|
||||
$this->authCheck();
|
||||
|
||||
return view('status.compose');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$this->authCheck();
|
||||
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$status = Status::findOrFail($request->input('item'));
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if($status->profile_id != $user->profile->id &&
|
||||
$user->is_admin == true &&
|
||||
$status->uri == null
|
||||
) {
|
||||
$media = $status->media;
|
||||
|
||||
$ai = new AccountInterstitial;
|
||||
$ai->user_id = $status->profile->user_id;
|
||||
$ai->type = 'post.removed';
|
||||
$ai->view = 'account.moderation.post.removed';
|
||||
$ai->item_type = 'App\Status';
|
||||
$ai->item_id = $status->id;
|
||||
$ai->has_media = (bool) $media->count();
|
||||
$ai->blurhash = $media->count() ? $media->first()->blurhash : null;
|
||||
$ai->meta = json_encode([
|
||||
'caption' => $status->caption,
|
||||
'created_at' => $status->created_at,
|
||||
'type' => $status->type,
|
||||
'url' => $status->url(),
|
||||
'is_nsfw' => $status->is_nsfw,
|
||||
'scope' => $status->scope,
|
||||
'reblog' => $status->reblog_of_id,
|
||||
'likes_count' => $status->likes_count,
|
||||
'reblogs_count' => $status->reblogs_count,
|
||||
]);
|
||||
$ai->save();
|
||||
|
||||
$u = $status->profile->user;
|
||||
$u->has_interstitial = true;
|
||||
$u->save();
|
||||
}
|
||||
|
||||
if($status->in_reply_to_id) {
|
||||
$parent = Status::find($status->in_reply_to_id);
|
||||
if($parent && ($parent->profile_id == $user->profile_id) || ($status->profile_id == $user->profile_id) || $user->is_admin) {
|
||||
Cache::forget('_api:statuses:recent_9:' . $status->profile_id);
|
||||
Cache::forget('profile:status_count:' . $status->profile_id);
|
||||
Cache::forget('profile:embed:' . $status->profile_id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
$status->uri ? RemoteStatusDelete::dispatch($status) : StatusDelete::dispatch($status);
|
||||
}
|
||||
} else if ($status->profile_id == $user->profile_id || $user->is_admin == true) {
|
||||
Cache::forget('_api:statuses:recent_9:' . $status->profile_id);
|
||||
Cache::forget('profile:status_count:' . $status->profile_id);
|
||||
Cache::forget('profile:embed:' . $status->profile_id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
$status->uri ? RemoteStatusDelete::dispatch($status) : StatusDelete::dispatch($status);
|
||||
}
|
||||
|
||||
if($request->wantsJson()) {
|
||||
return response()->json(['Status successfully deleted.']);
|
||||
} else {
|
||||
return redirect($user->url());
|
||||
}
|
||||
}
|
||||
|
||||
public function storeShare(Request $request)
|
||||
{
|
||||
$this->authCheck();
|
||||
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
$status = Status::whereScope('public')
|
||||
->findOrFail($request->input('item'));
|
||||
|
||||
$count = $status->reblogs_count;
|
||||
|
||||
$exists = Status::whereProfileId(Auth::user()->profile->id)
|
||||
->whereReblogOfId($status->id)
|
||||
->exists();
|
||||
if ($exists == true) {
|
||||
$shares = Status::whereProfileId(Auth::user()->profile->id)
|
||||
->whereReblogOfId($status->id)
|
||||
->get();
|
||||
foreach ($shares as $share) {
|
||||
UndoSharePipeline::dispatch($share);
|
||||
ReblogService::del($profile->id, $status->id);
|
||||
$count--;
|
||||
}
|
||||
} else {
|
||||
$share = new Status();
|
||||
$share->profile_id = $profile->id;
|
||||
$share->reblog_of_id = $status->id;
|
||||
$share->in_reply_to_profile_id = $status->profile_id;
|
||||
$share->type = 'share';
|
||||
$share->save();
|
||||
$count++;
|
||||
SharePipeline::dispatch($share);
|
||||
ReblogService::add($profile->id, $status->id);
|
||||
}
|
||||
|
||||
Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id);
|
||||
StatusService::del($status->id);
|
||||
|
||||
if ($request->ajax()) {
|
||||
$response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count];
|
||||
} else {
|
||||
$response = redirect($status->url());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function showActivityPub(Request $request, $status)
|
||||
{
|
||||
$object = $status->type == 'poll' ? new Question() : new Note();
|
||||
$fractal = new Fractal\Manager();
|
||||
$resource = new Fractal\Resource\Item($status, $object);
|
||||
$res = $fractal->createData($resource)->toArray();
|
||||
|
||||
return response()->json($res['data'], 200, ['Content-Type' => 'application/activity+json'], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
public function edit(Request $request, $username, $id)
|
||||
{
|
||||
$this->authCheck();
|
||||
$user = Auth::user()->profile;
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->with(['media'])
|
||||
->findOrFail($id);
|
||||
$licenses = License::get();
|
||||
return view('status.edit', compact('user', 'status', 'licenses'));
|
||||
}
|
||||
|
||||
public function editStore(Request $request, $username, $id)
|
||||
{
|
||||
$this->authCheck();
|
||||
$user = Auth::user()->profile;
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->with(['media'])
|
||||
->findOrFail($id);
|
||||
|
||||
$this->validate($request, [
|
||||
'license' => 'nullable|integer|min:1|max:16',
|
||||
]);
|
||||
|
||||
$licenseId = $request->input('license');
|
||||
|
||||
$status->media->each(function($media) use($licenseId) {
|
||||
$media->license = $licenseId;
|
||||
$media->save();
|
||||
Cache::forget('status:transformer:media:attachments:'.$media->status_id);
|
||||
});
|
||||
|
||||
return redirect($status->url());
|
||||
}
|
||||
|
||||
protected function authCheck()
|
||||
{
|
||||
if (Auth::check() == false) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
|
||||
protected function validateVisibility($visibility)
|
||||
{
|
||||
$allowed = ['public', 'unlisted', 'private'];
|
||||
return in_array($visibility, $allowed) ? $visibility : 'public';
|
||||
}
|
||||
|
||||
public static function mimeTypeCheck($mimes)
|
||||
{
|
||||
$allowed = explode(',', config_cache('pixelfed.media_types'));
|
||||
$count = count($mimes);
|
||||
$photos = 0;
|
||||
$videos = 0;
|
||||
foreach($mimes as $mime) {
|
||||
if(in_array($mime, $allowed) == false && $mime !== 'video/mp4') {
|
||||
continue;
|
||||
}
|
||||
if(str_contains($mime, 'image/')) {
|
||||
$photos++;
|
||||
}
|
||||
if(str_contains($mime, 'video/')) {
|
||||
$videos++;
|
||||
}
|
||||
}
|
||||
if($photos == 1 && $videos == 0) {
|
||||
return 'photo';
|
||||
}
|
||||
if($videos == 1 && $photos == 0) {
|
||||
return 'video';
|
||||
}
|
||||
if($photos > 1 && $videos == 0) {
|
||||
return 'photo:album';
|
||||
}
|
||||
if($videos > 1 && $photos == 0) {
|
||||
return 'video:album';
|
||||
}
|
||||
if($photos >= 1 && $videos >= 1) {
|
||||
return 'photo:video:album';
|
||||
}
|
||||
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function toggleVisibility(Request $request) {
|
||||
$this->authCheck();
|
||||
$this->validate($request, [
|
||||
'item' => 'required|string|min:1|max:20',
|
||||
'disableComments' => 'required|boolean'
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$id = $request->input('item');
|
||||
$state = $request->input('disableComments');
|
||||
|
||||
$status = Status::findOrFail($id);
|
||||
|
||||
if($status->profile_id != $user->profile->id && $user->is_admin == false) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$status->comments_disabled = $status->comments_disabled == true ? false : true;
|
||||
$status->save();
|
||||
|
||||
return response()->json([200]);
|
||||
}
|
||||
|
||||
public function storeView(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
|
||||
$views = $request->input('_v');
|
||||
$uid = $request->user()->profile_id;
|
||||
|
||||
if(empty($views) || !is_array($views)) {
|
||||
return response()->json(0);
|
||||
}
|
||||
|
||||
Cache::forget('profile:home-timeline-cursor:' . $request->user()->id);
|
||||
|
||||
foreach($views as $view) {
|
||||
if(!isset($view['sid']) || !isset($view['pid'])) {
|
||||
continue;
|
||||
}
|
||||
DB::transaction(function () use($view, $uid) {
|
||||
StatusView::firstOrCreate([
|
||||
'status_id' => $view['sid'],
|
||||
'status_profile_id' => $view['pid'],
|
||||
'profile_id' => $uid
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json(1);
|
||||
}
|
||||
public function show(Request $request, $username, $id)
|
||||
{
|
||||
// redirect authed users to Metro 2.0
|
||||
if ($request->user()) {
|
||||
// unless they force static view
|
||||
if (! $request->has('fs') || $request->input('fs') != '1') {
|
||||
return redirect('/i/web/post/'.$id);
|
||||
}
|
||||
}
|
||||
|
||||
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||
|
||||
if ($user->status != null) {
|
||||
return ProfileController::accountCheck($user);
|
||||
}
|
||||
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->whereNull('reblog_of_id')
|
||||
->whereIn('scope', ['public', 'unlisted', 'private'])
|
||||
->findOrFail($id);
|
||||
|
||||
if ($status->uri || $status->url) {
|
||||
$url = $status->uri ?? $status->url;
|
||||
if (ends_with($url, '/activity')) {
|
||||
$url = str_replace('/activity', '', $url);
|
||||
}
|
||||
|
||||
return redirect($url);
|
||||
}
|
||||
|
||||
if ($status->visibility == 'private' || $user->is_private) {
|
||||
if (! Auth::check()) {
|
||||
abort(404);
|
||||
}
|
||||
$pid = Auth::user()->profile;
|
||||
if ($user->followedBy($pid) == false && $user->id !== $pid->id && Auth::user()->is_admin == false) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
if ($status->type == 'archived') {
|
||||
if (Auth::user()->profile_id !== $status->profile_id) {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->user() && $request->user()->profile_id != $status->profile_id) {
|
||||
StatusView::firstOrCreate([
|
||||
'status_id' => $status->id,
|
||||
'status_profile_id' => $status->profile_id,
|
||||
'profile_id' => $request->user()->profile_id,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($request->wantsJson() && (bool) config_cache('federation.activitypub.enabled')) {
|
||||
return $this->showActivityPub($request, $status);
|
||||
}
|
||||
|
||||
$template = $status->in_reply_to_id ? 'status.reply' : 'status.show';
|
||||
|
||||
return view($template, compact('user', 'status'));
|
||||
}
|
||||
|
||||
public function shortcodeRedirect(Request $request, $id)
|
||||
{
|
||||
$hid = HashidService::decode($id);
|
||||
abort_if(! $hid, 404);
|
||||
|
||||
return redirect('/i/web/post/'.$hid);
|
||||
}
|
||||
|
||||
public function showId(int $id)
|
||||
{
|
||||
abort(404);
|
||||
$status = Status::whereNull('reblog_of_id')
|
||||
->whereIn('scope', ['public', 'unlisted'])
|
||||
->findOrFail($id);
|
||||
|
||||
return redirect($status->url());
|
||||
}
|
||||
|
||||
public function showEmbed(Request $request, $username, int $id)
|
||||
{
|
||||
if (! (bool) config_cache('instance.embed.post')) {
|
||||
$res = view('status.embed-removed');
|
||||
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
$status = StatusService::get($id);
|
||||
|
||||
if (
|
||||
! $status ||
|
||||
! isset($status['account'], $status['account']['id'], $status['local']) ||
|
||||
! $status['local'] ||
|
||||
strtolower($status['account']['username']) !== strtolower($username)
|
||||
) {
|
||||
$content = view('status.embed-removed');
|
||||
|
||||
return response($content, 404)->header('X-Frame-Options', 'ALLOWALL');
|
||||
}
|
||||
|
||||
$profile = AccountService::get($status['account']['id'], true);
|
||||
|
||||
if (! $profile || $profile['locked'] || ! $profile['local']) {
|
||||
$content = view('status.embed-removed');
|
||||
|
||||
return response($content)->header('X-Frame-Options', 'ALLOWALL');
|
||||
}
|
||||
|
||||
$aiCheck = Cache::remember('profile:ai-check:spam-login:'.$profile['id'], 3600, function () use ($profile) {
|
||||
$user = Profile::find($profile['id']);
|
||||
if (! $user) {
|
||||
return true;
|
||||
}
|
||||
$exists = AccountInterstitial::whereUserId($user->user_id)->where('is_spam', 1)->count();
|
||||
if ($exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if ($aiCheck) {
|
||||
$res = view('status.embed-removed');
|
||||
|
||||
return response($res)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
$status = StatusService::get($id);
|
||||
|
||||
if (
|
||||
! $status ||
|
||||
! isset($status['account'], $status['account']['id']) ||
|
||||
intval($status['account']['id']) !== intval($profile['id']) ||
|
||||
$status['sensitive'] ||
|
||||
$status['visibility'] !== 'public' ||
|
||||
$status['pf_type'] !== 'photo'
|
||||
) {
|
||||
$content = view('status.embed-removed');
|
||||
|
||||
return response($content)->header('X-Frame-Options', 'ALLOWALL');
|
||||
}
|
||||
|
||||
$showLikes = $request->filled('likes') && $request->likes == true;
|
||||
$showCaption = $request->filled('caption') && $request->caption !== false;
|
||||
$layout = $request->filled('layout') && $request->layout == 'compact' ? 'compact' : 'full';
|
||||
$content = view('status.embed', compact('status', 'showLikes', 'showCaption', 'layout'));
|
||||
|
||||
return response($content)->withHeaders(['X-Frame-Options' => 'ALLOWALL']);
|
||||
}
|
||||
|
||||
public function showObject(Request $request, $username, int $id)
|
||||
{
|
||||
$user = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
|
||||
|
||||
if ($user->status != null) {
|
||||
return ProfileController::accountCheck($user);
|
||||
}
|
||||
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->whereNotIn('visibility', ['draft', 'direct'])
|
||||
->findOrFail($id);
|
||||
|
||||
abort_if($status->uri, 404);
|
||||
|
||||
if ($status->visibility == 'private' || $user->is_private) {
|
||||
if (! Auth::check()) {
|
||||
abort(403);
|
||||
}
|
||||
$pid = Auth::user()->profile;
|
||||
if ($user->followedBy($pid) == false && $user->id !== $pid->id) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->showActivityPub($request, $status);
|
||||
}
|
||||
|
||||
public function compose()
|
||||
{
|
||||
$this->authCheck();
|
||||
|
||||
return view('status.compose');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
$this->authCheck();
|
||||
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$status = Status::findOrFail($request->input('item'));
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if ($status->profile_id != $user->profile->id &&
|
||||
$user->is_admin == true &&
|
||||
$status->uri == null
|
||||
) {
|
||||
$media = $status->media;
|
||||
|
||||
$ai = new AccountInterstitial;
|
||||
$ai->user_id = $status->profile->user_id;
|
||||
$ai->type = 'post.removed';
|
||||
$ai->view = 'account.moderation.post.removed';
|
||||
$ai->item_type = 'App\Status';
|
||||
$ai->item_id = $status->id;
|
||||
$ai->has_media = (bool) $media->count();
|
||||
$ai->blurhash = $media->count() ? $media->first()->blurhash : null;
|
||||
$ai->meta = json_encode([
|
||||
'caption' => $status->caption,
|
||||
'created_at' => $status->created_at,
|
||||
'type' => $status->type,
|
||||
'url' => $status->url(),
|
||||
'is_nsfw' => $status->is_nsfw,
|
||||
'scope' => $status->scope,
|
||||
'reblog' => $status->reblog_of_id,
|
||||
'likes_count' => $status->likes_count,
|
||||
'reblogs_count' => $status->reblogs_count,
|
||||
]);
|
||||
$ai->save();
|
||||
|
||||
$u = $status->profile->user;
|
||||
$u->has_interstitial = true;
|
||||
$u->save();
|
||||
}
|
||||
|
||||
if ($status->in_reply_to_id) {
|
||||
$parent = Status::find($status->in_reply_to_id);
|
||||
if ($parent && ($parent->profile_id == $user->profile_id) || ($status->profile_id == $user->profile_id) || $user->is_admin) {
|
||||
Cache::forget('_api:statuses:recent_9:'.$status->profile_id);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
Cache::forget('profile:embed:'.$status->profile_id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
$status->uri ? RemoteStatusDelete::dispatch($status) : StatusDelete::dispatch($status);
|
||||
}
|
||||
} elseif ($status->profile_id == $user->profile_id || $user->is_admin == true) {
|
||||
Cache::forget('_api:statuses:recent_9:'.$status->profile_id);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
Cache::forget('profile:embed:'.$status->profile_id);
|
||||
StatusService::del($status->id, true);
|
||||
Cache::forget('profile:status_count:'.$status->profile_id);
|
||||
$status->uri ? RemoteStatusDelete::dispatch($status) : StatusDelete::dispatch($status);
|
||||
}
|
||||
|
||||
if ($request->wantsJson()) {
|
||||
return response()->json(['Status successfully deleted.']);
|
||||
} else {
|
||||
return redirect($user->url());
|
||||
}
|
||||
}
|
||||
|
||||
public function storeShare(Request $request)
|
||||
{
|
||||
$this->authCheck();
|
||||
|
||||
$this->validate($request, [
|
||||
'item' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
$status = Status::whereScope('public')
|
||||
->findOrFail($request->input('item'));
|
||||
|
||||
$count = $status->reblogs_count;
|
||||
|
||||
$exists = Status::whereProfileId(Auth::user()->profile->id)
|
||||
->whereReblogOfId($status->id)
|
||||
->exists();
|
||||
if ($exists == true) {
|
||||
$shares = Status::whereProfileId(Auth::user()->profile->id)
|
||||
->whereReblogOfId($status->id)
|
||||
->get();
|
||||
foreach ($shares as $share) {
|
||||
UndoSharePipeline::dispatch($share);
|
||||
ReblogService::del($profile->id, $status->id);
|
||||
$count--;
|
||||
}
|
||||
} else {
|
||||
$share = new Status();
|
||||
$share->profile_id = $profile->id;
|
||||
$share->reblog_of_id = $status->id;
|
||||
$share->in_reply_to_profile_id = $status->profile_id;
|
||||
$share->type = 'share';
|
||||
$share->save();
|
||||
$count++;
|
||||
SharePipeline::dispatch($share);
|
||||
ReblogService::add($profile->id, $status->id);
|
||||
}
|
||||
|
||||
Cache::forget('status:'.$status->id.':sharedby:userid:'.$user->id);
|
||||
StatusService::del($status->id);
|
||||
|
||||
if ($request->ajax()) {
|
||||
$response = ['code' => 200, 'msg' => 'Share saved', 'count' => $count];
|
||||
} else {
|
||||
$response = redirect($status->url());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function showActivityPub(Request $request, $status)
|
||||
{
|
||||
$object = $status->type == 'poll' ? new Question() : new Note();
|
||||
$fractal = new Fractal\Manager();
|
||||
$resource = new Fractal\Resource\Item($status, $object);
|
||||
$res = $fractal->createData($resource)->toArray();
|
||||
|
||||
return response()->json($res['data'], 200, ['Content-Type' => 'application/activity+json'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
public function edit(Request $request, $username, $id)
|
||||
{
|
||||
$this->authCheck();
|
||||
$user = Auth::user()->profile;
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->with(['media'])
|
||||
->findOrFail($id);
|
||||
$licenses = License::get();
|
||||
|
||||
return view('status.edit', compact('user', 'status', 'licenses'));
|
||||
}
|
||||
|
||||
public function editStore(Request $request, $username, $id)
|
||||
{
|
||||
$this->authCheck();
|
||||
$user = Auth::user()->profile;
|
||||
$status = Status::whereProfileId($user->id)
|
||||
->with(['media'])
|
||||
->findOrFail($id);
|
||||
|
||||
$this->validate($request, [
|
||||
'license' => 'nullable|integer|min:1|max:16',
|
||||
]);
|
||||
|
||||
$licenseId = $request->input('license');
|
||||
|
||||
$status->media->each(function ($media) use ($licenseId) {
|
||||
$media->license = $licenseId;
|
||||
$media->save();
|
||||
Cache::forget('status:transformer:media:attachments:'.$media->status_id);
|
||||
});
|
||||
|
||||
return redirect($status->url());
|
||||
}
|
||||
|
||||
protected function authCheck()
|
||||
{
|
||||
if (Auth::check() == false) {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
|
||||
protected function validateVisibility($visibility)
|
||||
{
|
||||
$allowed = ['public', 'unlisted', 'private'];
|
||||
|
||||
return in_array($visibility, $allowed) ? $visibility : 'public';
|
||||
}
|
||||
|
||||
public static function mimeTypeCheck($mimes)
|
||||
{
|
||||
$allowed = explode(',', config_cache('pixelfed.media_types'));
|
||||
$count = count($mimes);
|
||||
$photos = 0;
|
||||
$videos = 0;
|
||||
foreach ($mimes as $mime) {
|
||||
if (in_array($mime, $allowed) == false && $mime !== 'video/mp4') {
|
||||
continue;
|
||||
}
|
||||
if (str_contains($mime, 'image/')) {
|
||||
$photos++;
|
||||
}
|
||||
if (str_contains($mime, 'video/')) {
|
||||
$videos++;
|
||||
}
|
||||
}
|
||||
if ($photos == 1 && $videos == 0) {
|
||||
return 'photo';
|
||||
}
|
||||
if ($videos == 1 && $photos == 0) {
|
||||
return 'video';
|
||||
}
|
||||
if ($photos > 1 && $videos == 0) {
|
||||
return 'photo:album';
|
||||
}
|
||||
if ($videos > 1 && $photos == 0) {
|
||||
return 'video:album';
|
||||
}
|
||||
if ($photos >= 1 && $videos >= 1) {
|
||||
return 'photo:video:album';
|
||||
}
|
||||
|
||||
return 'text';
|
||||
}
|
||||
|
||||
public function toggleVisibility(Request $request)
|
||||
{
|
||||
$this->authCheck();
|
||||
$this->validate($request, [
|
||||
'item' => 'required|string|min:1|max:20',
|
||||
'disableComments' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
$id = $request->input('item');
|
||||
$state = $request->input('disableComments');
|
||||
|
||||
$status = Status::findOrFail($id);
|
||||
|
||||
if ($status->profile_id != $user->profile->id && $user->is_admin == false) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$status->comments_disabled = $status->comments_disabled == true ? false : true;
|
||||
$status->save();
|
||||
|
||||
return response()->json([200]);
|
||||
}
|
||||
|
||||
public function storeView(Request $request)
|
||||
{
|
||||
abort_if(! $request->user(), 403);
|
||||
|
||||
$views = $request->input('_v');
|
||||
$uid = $request->user()->profile_id;
|
||||
|
||||
if (empty($views) || ! is_array($views)) {
|
||||
return response()->json(0);
|
||||
}
|
||||
|
||||
Cache::forget('profile:home-timeline-cursor:'.$request->user()->id);
|
||||
|
||||
foreach ($views as $view) {
|
||||
if (! isset($view['sid']) || ! isset($view['pid'])) {
|
||||
continue;
|
||||
}
|
||||
DB::transaction(function () use ($view, $uid) {
|
||||
StatusView::firstOrCreate([
|
||||
'status_id' => $view['sid'],
|
||||
'status_profile_id' => $view['pid'],
|
||||
'profile_id' => $uid,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
return response()->json(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,54 +2,56 @@
|
|||
|
||||
namespace App\Http\Controllers\Stories;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Models\Conversation;
|
||||
use App\DirectMessage;
|
||||
use App\Notification;
|
||||
use App\Story;
|
||||
use App\Status;
|
||||
use App\StoryView;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\StoryView as StoryViewResource;
|
||||
use App\Jobs\StoryPipeline\StoryDelete;
|
||||
use App\Jobs\StoryPipeline\StoryFanout;
|
||||
use App\Jobs\StoryPipeline\StoryReplyDeliver;
|
||||
use App\Jobs\StoryPipeline\StoryViewDeliver;
|
||||
use App\Models\Conversation;
|
||||
use App\Notification;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\MediaPathService;
|
||||
use App\Services\StoryService;
|
||||
use App\Http\Resources\StoryView as StoryViewResource;
|
||||
use App\Status;
|
||||
use App\Story;
|
||||
use App\StoryView;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StoryApiV1Controller extends Controller
|
||||
{
|
||||
const RECENT_KEY = 'pf:stories:recent-by-id:';
|
||||
|
||||
const RECENT_TTL = 300;
|
||||
|
||||
public function carousel(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
|
||||
if(config('database.default') == 'pgsql') {
|
||||
$s = Cache::remember(self::RECENT_KEY . $pid, self::RECENT_TTL, function() use($pid) {
|
||||
if (config('database.default') == 'pgsql') {
|
||||
$s = Cache::remember(self::RECENT_KEY.$pid, self::RECENT_TTL, function () use ($pid) {
|
||||
return Story::select('stories.*', 'followers.following_id')
|
||||
->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
|
||||
->where('followers.profile_id', $pid)
|
||||
->where('stories.active', true)
|
||||
->map(function($s) {
|
||||
$r = new \StdClass;
|
||||
->map(function ($s) {
|
||||
$r = new \StdClass;
|
||||
$r->id = $s->id;
|
||||
$r->profile_id = $s->profile_id;
|
||||
$r->type = $s->type;
|
||||
$r->path = $s->path;
|
||||
|
||||
return $r;
|
||||
})
|
||||
->unique('profile_id');
|
||||
});
|
||||
} else {
|
||||
$s = Cache::remember(self::RECENT_KEY . $pid, self::RECENT_TTL, function() use($pid) {
|
||||
$s = Cache::remember(self::RECENT_KEY.$pid, self::RECENT_TTL, function () use ($pid) {
|
||||
return Story::select('stories.*', 'followers.following_id')
|
||||
->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
|
||||
->where('followers.profile_id', $pid)
|
||||
|
@ -59,9 +61,9 @@ class StoryApiV1Controller extends Controller
|
|||
});
|
||||
}
|
||||
|
||||
$nodes = $s->map(function($s) use($pid) {
|
||||
$nodes = $s->map(function ($s) use ($pid) {
|
||||
$profile = AccountService::get($s->profile_id, true);
|
||||
if(!$profile || !isset($profile['id'])) {
|
||||
if (! $profile || ! isset($profile['id'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -72,50 +74,51 @@ class StoryApiV1Controller extends Controller
|
|||
'src' => url(Storage::url($s->path)),
|
||||
'duration' => $s->duration ?? 3,
|
||||
'seen' => StoryService::hasSeen($pid, $s->id),
|
||||
'created_at' => $s->created_at->format('c')
|
||||
'created_at' => $s->created_at->format('c'),
|
||||
];
|
||||
})
|
||||
->filter()
|
||||
->groupBy('pid')
|
||||
->map(function($item) use($pid) {
|
||||
$profile = AccountService::get($item[0]['pid'], true);
|
||||
$url = $profile['local'] ? url("/stories/{$profile['username']}") :
|
||||
url("/i/rs/{$profile['id']}");
|
||||
return [
|
||||
'id' => 'pfs:' . $profile['id'],
|
||||
'user' => [
|
||||
'id' => (string) $profile['id'],
|
||||
'username' => $profile['username'],
|
||||
'username_acct' => $profile['acct'],
|
||||
'avatar' => $profile['avatar'],
|
||||
'local' => $profile['local'],
|
||||
'is_author' => $profile['id'] == $pid
|
||||
],
|
||||
'nodes' => $item,
|
||||
'url' => $url,
|
||||
'seen' => StoryService::hasSeen($pid, StoryService::latest($profile['id'])),
|
||||
];
|
||||
})
|
||||
->sortBy('seen')
|
||||
->values();
|
||||
->filter()
|
||||
->groupBy('pid')
|
||||
->map(function ($item) use ($pid) {
|
||||
$profile = AccountService::get($item[0]['pid'], true);
|
||||
$url = $profile['local'] ? url("/stories/{$profile['username']}") :
|
||||
url("/i/rs/{$profile['id']}");
|
||||
|
||||
return [
|
||||
'id' => 'pfs:'.$profile['id'],
|
||||
'user' => [
|
||||
'id' => (string) $profile['id'],
|
||||
'username' => $profile['username'],
|
||||
'username_acct' => $profile['acct'],
|
||||
'avatar' => $profile['avatar'],
|
||||
'local' => $profile['local'],
|
||||
'is_author' => $profile['id'] == $pid,
|
||||
],
|
||||
'nodes' => $item,
|
||||
'url' => $url,
|
||||
'seen' => StoryService::hasSeen($pid, StoryService::latest($profile['id'])),
|
||||
];
|
||||
})
|
||||
->sortBy('seen')
|
||||
->values();
|
||||
|
||||
$res = [
|
||||
'self' => [],
|
||||
'nodes' => $nodes,
|
||||
];
|
||||
|
||||
if(Story::whereProfileId($pid)->whereActive(true)->exists()) {
|
||||
if (Story::whereProfileId($pid)->whereActive(true)->exists()) {
|
||||
$selfStories = Story::whereProfileId($pid)
|
||||
->whereActive(true)
|
||||
->get()
|
||||
->map(function($s) use($pid) {
|
||||
->map(function ($s) {
|
||||
return [
|
||||
'id' => (string) $s->id,
|
||||
'type' => $s->type,
|
||||
'src' => url(Storage::url($s->path)),
|
||||
'duration' => $s->duration,
|
||||
'seen' => true,
|
||||
'created_at' => $s->created_at->format('c')
|
||||
'created_at' => $s->created_at->format('c'),
|
||||
];
|
||||
})
|
||||
->sortBy('id')
|
||||
|
@ -127,38 +130,40 @@ class StoryApiV1Controller extends Controller
|
|||
'username' => $selfProfile['acct'],
|
||||
'avatar' => $selfProfile['avatar'],
|
||||
'local' => $selfProfile['local'],
|
||||
'is_author' => true
|
||||
'is_author' => true,
|
||||
],
|
||||
|
||||
'nodes' => $selfStories,
|
||||
];
|
||||
}
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
public function selfCarousel(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
$pid = $request->user()->profile_id;
|
||||
|
||||
if(config('database.default') == 'pgsql') {
|
||||
$s = Cache::remember(self::RECENT_KEY . $pid, self::RECENT_TTL, function() use($pid) {
|
||||
if (config('database.default') == 'pgsql') {
|
||||
$s = Cache::remember(self::RECENT_KEY.$pid, self::RECENT_TTL, function () use ($pid) {
|
||||
return Story::select('stories.*', 'followers.following_id')
|
||||
->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
|
||||
->where('followers.profile_id', $pid)
|
||||
->where('stories.active', true)
|
||||
->map(function($s) {
|
||||
$r = new \StdClass;
|
||||
->map(function ($s) {
|
||||
$r = new \StdClass;
|
||||
$r->id = $s->id;
|
||||
$r->profile_id = $s->profile_id;
|
||||
$r->type = $s->type;
|
||||
$r->path = $s->path;
|
||||
|
||||
return $r;
|
||||
})
|
||||
->unique('profile_id');
|
||||
});
|
||||
} else {
|
||||
$s = Cache::remember(self::RECENT_KEY . $pid, self::RECENT_TTL, function() use($pid) {
|
||||
$s = Cache::remember(self::RECENT_KEY.$pid, self::RECENT_TTL, function () use ($pid) {
|
||||
return Story::select('stories.*', 'followers.following_id')
|
||||
->leftJoin('followers', 'followers.following_id', 'stories.profile_id')
|
||||
->where('followers.profile_id', $pid)
|
||||
|
@ -168,9 +173,9 @@ class StoryApiV1Controller extends Controller
|
|||
});
|
||||
}
|
||||
|
||||
$nodes = $s->map(function($s) use($pid) {
|
||||
$nodes = $s->map(function ($s) use ($pid) {
|
||||
$profile = AccountService::get($s->profile_id, true);
|
||||
if(!$profile || !isset($profile['id'])) {
|
||||
if (! $profile || ! isset($profile['id'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -181,32 +186,33 @@ class StoryApiV1Controller extends Controller
|
|||
'src' => url(Storage::url($s->path)),
|
||||
'duration' => $s->duration ?? 3,
|
||||
'seen' => StoryService::hasSeen($pid, $s->id),
|
||||
'created_at' => $s->created_at->format('c')
|
||||
'created_at' => $s->created_at->format('c'),
|
||||
];
|
||||
})
|
||||
->filter()
|
||||
->groupBy('pid')
|
||||
->map(function($item) use($pid) {
|
||||
$profile = AccountService::get($item[0]['pid'], true);
|
||||
$url = $profile['local'] ? url("/stories/{$profile['username']}") :
|
||||
url("/i/rs/{$profile['id']}");
|
||||
return [
|
||||
'id' => 'pfs:' . $profile['id'],
|
||||
'user' => [
|
||||
'id' => (string) $profile['id'],
|
||||
'username' => $profile['username'],
|
||||
'username_acct' => $profile['acct'],
|
||||
'avatar' => $profile['avatar'],
|
||||
'local' => $profile['local'],
|
||||
'is_author' => $profile['id'] == $pid
|
||||
],
|
||||
'nodes' => $item,
|
||||
'url' => $url,
|
||||
'seen' => StoryService::hasSeen($pid, StoryService::latest($profile['id'])),
|
||||
];
|
||||
})
|
||||
->sortBy('seen')
|
||||
->values();
|
||||
->filter()
|
||||
->groupBy('pid')
|
||||
->map(function ($item) use ($pid) {
|
||||
$profile = AccountService::get($item[0]['pid'], true);
|
||||
$url = $profile['local'] ? url("/stories/{$profile['username']}") :
|
||||
url("/i/rs/{$profile['id']}");
|
||||
|
||||
return [
|
||||
'id' => 'pfs:'.$profile['id'],
|
||||
'user' => [
|
||||
'id' => (string) $profile['id'],
|
||||
'username' => $profile['username'],
|
||||
'username_acct' => $profile['acct'],
|
||||
'avatar' => $profile['avatar'],
|
||||
'local' => $profile['local'],
|
||||
'is_author' => $profile['id'] == $pid,
|
||||
],
|
||||
'nodes' => $item,
|
||||
'url' => $url,
|
||||
'seen' => StoryService::hasSeen($pid, StoryService::latest($profile['id'])),
|
||||
];
|
||||
})
|
||||
->sortBy('seen')
|
||||
->values();
|
||||
|
||||
$selfProfile = AccountService::get($pid, true);
|
||||
$res = [
|
||||
|
@ -216,7 +222,7 @@ class StoryApiV1Controller extends Controller
|
|||
'username' => $selfProfile['acct'],
|
||||
'avatar' => $selfProfile['avatar'],
|
||||
'local' => $selfProfile['local'],
|
||||
'is_author' => true
|
||||
'is_author' => true,
|
||||
],
|
||||
|
||||
'nodes' => [],
|
||||
|
@ -224,40 +230,41 @@ class StoryApiV1Controller extends Controller
|
|||
'nodes' => $nodes,
|
||||
];
|
||||
|
||||
if(Story::whereProfileId($pid)->whereActive(true)->exists()) {
|
||||
if (Story::whereProfileId($pid)->whereActive(true)->exists()) {
|
||||
$selfStories = Story::whereProfileId($pid)
|
||||
->whereActive(true)
|
||||
->get()
|
||||
->map(function($s) use($pid) {
|
||||
->map(function ($s) {
|
||||
return [
|
||||
'id' => (string) $s->id,
|
||||
'type' => $s->type,
|
||||
'src' => url(Storage::url($s->path)),
|
||||
'duration' => $s->duration,
|
||||
'seen' => true,
|
||||
'created_at' => $s->created_at->format('c')
|
||||
'created_at' => $s->created_at->format('c'),
|
||||
];
|
||||
})
|
||||
->sortBy('id')
|
||||
->values();
|
||||
$res['self']['nodes'] = $selfStories;
|
||||
}
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'file' => function() {
|
||||
'file' => function () {
|
||||
return [
|
||||
'required',
|
||||
'mimetypes:image/jpeg,image/png,video/mp4',
|
||||
'max:' . config_cache('pixelfed.max_photo_size'),
|
||||
'max:'.config_cache('pixelfed.max_photo_size'),
|
||||
];
|
||||
},
|
||||
'duration' => 'sometimes|integer|min:0|max:30'
|
||||
'duration' => 'sometimes|integer|min:0|max:30',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
@ -267,7 +274,7 @@ class StoryApiV1Controller extends Controller
|
|||
->where('expires_at', '>', now())
|
||||
->count();
|
||||
|
||||
if($count >= Story::MAX_PER_DAY) {
|
||||
if ($count >= Story::MAX_PER_DAY) {
|
||||
abort(418, 'You have reached your limit for new Stories today.');
|
||||
}
|
||||
|
||||
|
@ -277,7 +284,7 @@ class StoryApiV1Controller extends Controller
|
|||
$story = new Story();
|
||||
$story->duration = $request->input('duration', 3);
|
||||
$story->profile_id = $user->profile_id;
|
||||
$story->type = Str::endsWith($photo->getMimeType(), 'mp4') ? 'video' :'photo';
|
||||
$story->type = Str::endsWith($photo->getMimeType(), 'mp4') ? 'video' : 'photo';
|
||||
$story->mime = $photo->getMimeType();
|
||||
$story->path = $path;
|
||||
$story->local = true;
|
||||
|
@ -290,10 +297,10 @@ class StoryApiV1Controller extends Controller
|
|||
|
||||
$res = [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully added',
|
||||
'msg' => 'Successfully added',
|
||||
'media_id' => (string) $story->id,
|
||||
'media_url' => url(Storage::url($url)) . '?v=' . time(),
|
||||
'media_type' => $story->type
|
||||
'media_url' => url(Storage::url($url)).'?v='.time(),
|
||||
'media_type' => $story->type,
|
||||
];
|
||||
|
||||
return $res;
|
||||
|
@ -301,13 +308,13 @@ class StoryApiV1Controller extends Controller
|
|||
|
||||
public function publish(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'media_id' => 'required',
|
||||
'duration' => 'required|integer|min:0|max:30',
|
||||
'can_reply' => 'required|boolean',
|
||||
'can_react' => 'required|boolean'
|
||||
'can_react' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$id = $request->input('media_id');
|
||||
|
@ -327,13 +334,13 @@ class StoryApiV1Controller extends Controller
|
|||
|
||||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully published',
|
||||
'msg' => 'Successfully published',
|
||||
];
|
||||
}
|
||||
|
||||
public function delete(Request $request, $id)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
|
@ -346,16 +353,16 @@ class StoryApiV1Controller extends Controller
|
|||
|
||||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully deleted'
|
||||
'msg' => 'Successfully deleted',
|
||||
];
|
||||
}
|
||||
|
||||
public function viewed(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'id' => 'required|min:1',
|
||||
'id' => 'required|min:1',
|
||||
]);
|
||||
$id = $request->input('id');
|
||||
|
||||
|
@ -367,44 +374,45 @@ class StoryApiV1Controller extends Controller
|
|||
|
||||
$profile = $story->profile;
|
||||
|
||||
if($story->profile_id == $authed->id) {
|
||||
if ($story->profile_id == $authed->id) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$publicOnly = (bool) $profile->followedBy($authed);
|
||||
abort_if(!$publicOnly, 403);
|
||||
abort_if(! $publicOnly, 403);
|
||||
|
||||
$v = StoryView::firstOrCreate([
|
||||
'story_id' => $id,
|
||||
'profile_id' => $authed->id
|
||||
'profile_id' => $authed->id,
|
||||
]);
|
||||
|
||||
if($v->wasRecentlyCreated) {
|
||||
if ($v->wasRecentlyCreated) {
|
||||
Story::findOrFail($story->id)->increment('view_count');
|
||||
|
||||
if($story->local == false) {
|
||||
if ($story->local == false) {
|
||||
StoryViewDeliver::dispatch($story, $authed)->onQueue('story');
|
||||
}
|
||||
}
|
||||
|
||||
Cache::forget('stories:recent:by_id:' . $authed->id);
|
||||
Cache::forget('stories:recent:by_id:'.$authed->id);
|
||||
StoryService::addSeen($authed->id, $story->id);
|
||||
|
||||
return ['code' => 200];
|
||||
}
|
||||
|
||||
public function comment(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
$this->validate($request, [
|
||||
'sid' => 'required',
|
||||
'caption' => 'required|string'
|
||||
'caption' => 'required|string',
|
||||
]);
|
||||
$pid = $request->user()->profile_id;
|
||||
$text = $request->input('caption');
|
||||
|
||||
$story = Story::findOrFail($request->input('sid'));
|
||||
|
||||
abort_if(!$story->can_reply, 422);
|
||||
abort_if(! $story->can_reply, 422);
|
||||
|
||||
$status = new Status;
|
||||
$status->type = 'story:reply';
|
||||
|
@ -415,7 +423,7 @@ class StoryApiV1Controller extends Controller
|
|||
$status->visibility = 'direct';
|
||||
$status->in_reply_to_profile_id = $story->profile_id;
|
||||
$status->entities = json_encode([
|
||||
'story_id' => $story->id
|
||||
'story_id' => $story->id,
|
||||
]);
|
||||
$status->save();
|
||||
|
||||
|
@ -429,24 +437,24 @@ class StoryApiV1Controller extends Controller
|
|||
'story_actor_username' => $request->user()->username,
|
||||
'story_id' => $story->id,
|
||||
'story_media_url' => url(Storage::url($story->path)),
|
||||
'caption' => $text
|
||||
'caption' => $text,
|
||||
]);
|
||||
$dm->save();
|
||||
|
||||
Conversation::updateOrInsert(
|
||||
[
|
||||
'to_id' => $story->profile_id,
|
||||
'from_id' => $pid
|
||||
'from_id' => $pid,
|
||||
],
|
||||
[
|
||||
'type' => 'story:comment',
|
||||
'status_id' => $status->id,
|
||||
'dm_id' => $dm->id,
|
||||
'is_hidden' => false
|
||||
'is_hidden' => false,
|
||||
]
|
||||
);
|
||||
|
||||
if($story->local) {
|
||||
if ($story->local) {
|
||||
$n = new Notification;
|
||||
$n->profile_id = $dm->to_id;
|
||||
$n->actor_id = $dm->from_id;
|
||||
|
@ -460,33 +468,35 @@ class StoryApiV1Controller extends Controller
|
|||
|
||||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Sent!'
|
||||
'msg' => 'Sent!',
|
||||
];
|
||||
}
|
||||
|
||||
protected function storeMedia($photo, $user)
|
||||
{
|
||||
$mimes = explode(',', config_cache('pixelfed.media_types'));
|
||||
if(in_array($photo->getMimeType(), [
|
||||
if (in_array($photo->getMimeType(), [
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
'video/mp4'
|
||||
'video/mp4',
|
||||
]) == false) {
|
||||
abort(400, 'Invalid media type');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$storagePath = MediaPathService::story($user->profile);
|
||||
$path = $photo->storePubliclyAs($storagePath, Str::random(random_int(2, 12)) . '_' . Str::random(random_int(32, 35)) . '_' . Str::random(random_int(1, 14)) . '.' . $photo->extension());
|
||||
$path = $photo->storePubliclyAs($storagePath, Str::random(random_int(2, 12)).'_'.Str::random(random_int(32, 35)).'_'.Str::random(random_int(1, 14)).'.'.$photo->extension());
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function viewers(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'sid' => 'required|string|min:1|max:50'
|
||||
'sid' => 'required|string|min:1|max:50',
|
||||
]);
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
|
|
|
@ -2,59 +2,52 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Media;
|
||||
use App\Profile;
|
||||
use App\Report;
|
||||
use App\DirectMessage;
|
||||
use App\Notification;
|
||||
use App\Status;
|
||||
use App\Story;
|
||||
use App\StoryView;
|
||||
use App\Models\Poll;
|
||||
use App\Models\PollVote;
|
||||
use App\Services\ProfileService;
|
||||
use App\Services\StoryService;
|
||||
use Cache, Storage;
|
||||
use Image as Intervention;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\MediaPathService;
|
||||
use FFMpeg;
|
||||
use FFMpeg\Coordinate\Dimension;
|
||||
use FFMpeg\Format\Video\X264;
|
||||
use App\Jobs\StoryPipeline\StoryDelete;
|
||||
use App\Jobs\StoryPipeline\StoryFanout;
|
||||
use App\Jobs\StoryPipeline\StoryReactionDeliver;
|
||||
use App\Jobs\StoryPipeline\StoryReplyDeliver;
|
||||
use App\Jobs\StoryPipeline\StoryFanout;
|
||||
use App\Jobs\StoryPipeline\StoryDelete;
|
||||
use ImageOptimizer;
|
||||
use App\Models\Conversation;
|
||||
use App\Models\Poll;
|
||||
use App\Models\PollVote;
|
||||
use App\Notification;
|
||||
use App\Report;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\MediaPathService;
|
||||
use App\Services\StoryService;
|
||||
use App\Services\UserRoleService;
|
||||
use App\Status;
|
||||
use App\Story;
|
||||
use FFMpeg;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Image as Intervention;
|
||||
use Storage;
|
||||
|
||||
class StoryComposeController extends Controller
|
||||
{
|
||||
public function apiV1Add(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'file' => function() {
|
||||
'file' => function () {
|
||||
return [
|
||||
'required',
|
||||
'mimetypes:image/jpeg,image/png,video/mp4',
|
||||
'max:' . config_cache('pixelfed.max_photo_size'),
|
||||
'max:'.config_cache('pixelfed.max_photo_size'),
|
||||
];
|
||||
},
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$count = Story::whereProfileId($user->profile_id)
|
||||
->whereActive(true)
|
||||
->where('expires_at', '>', now())
|
||||
->count();
|
||||
|
||||
if($count >= Story::MAX_PER_DAY) {
|
||||
if ($count >= Story::MAX_PER_DAY) {
|
||||
abort(418, 'You have reached your limit for new Stories today.');
|
||||
}
|
||||
|
||||
|
@ -64,7 +57,7 @@ class StoryComposeController extends Controller
|
|||
$story = new Story();
|
||||
$story->duration = 3;
|
||||
$story->profile_id = $user->profile_id;
|
||||
$story->type = Str::endsWith($photo->getMimeType(), 'mp4') ? 'video' :'photo';
|
||||
$story->type = Str::endsWith($photo->getMimeType(), 'mp4') ? 'video' : 'photo';
|
||||
$story->mime = $photo->getMimeType();
|
||||
$story->path = $path;
|
||||
$story->local = true;
|
||||
|
@ -77,21 +70,22 @@ class StoryComposeController extends Controller
|
|||
|
||||
$res = [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully added',
|
||||
'msg' => 'Successfully added',
|
||||
'media_id' => (string) $story->id,
|
||||
'media_url' => url(Storage::url($url)) . '?v=' . time(),
|
||||
'media_type' => $story->type
|
||||
'media_url' => url(Storage::url($url)).'?v='.time(),
|
||||
'media_type' => $story->type,
|
||||
];
|
||||
|
||||
if($story->type === 'video') {
|
||||
if ($story->type === 'video') {
|
||||
$video = FFMpeg::open($path);
|
||||
$duration = $video->getDurationInSeconds();
|
||||
$res['media_duration'] = $duration;
|
||||
if($duration > 500) {
|
||||
if ($duration > 500) {
|
||||
Storage::delete($story->path);
|
||||
$story->delete();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Video duration cannot exceed 60 seconds'
|
||||
'message' => 'Video duration cannot exceed 60 seconds',
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
@ -102,37 +96,39 @@ class StoryComposeController extends Controller
|
|||
protected function storePhoto($photo, $user)
|
||||
{
|
||||
$mimes = explode(',', config_cache('pixelfed.media_types'));
|
||||
if(in_array($photo->getMimeType(), [
|
||||
if (in_array($photo->getMimeType(), [
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
'video/mp4'
|
||||
'video/mp4',
|
||||
]) == false) {
|
||||
abort(400, 'Invalid media type');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$storagePath = MediaPathService::story($user->profile);
|
||||
$path = $photo->storePubliclyAs($storagePath, Str::random(random_int(2, 12)) . '_' . Str::random(random_int(32, 35)) . '_' . Str::random(random_int(1, 14)) . '.' . $photo->extension());
|
||||
if(in_array($photo->getMimeType(), ['image/jpeg','image/png'])) {
|
||||
$fpath = storage_path('app/' . $path);
|
||||
$path = $photo->storePubliclyAs($storagePath, Str::random(random_int(2, 12)).'_'.Str::random(random_int(32, 35)).'_'.Str::random(random_int(1, 14)).'.'.$photo->extension());
|
||||
if (in_array($photo->getMimeType(), ['image/jpeg', 'image/png'])) {
|
||||
$fpath = storage_path('app/'.$path);
|
||||
$img = Intervention::make($fpath);
|
||||
$img->orientate();
|
||||
$img->save($fpath, config_cache('pixelfed.image_quality'));
|
||||
$img->destroy();
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function cropPhoto(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'media_id' => 'required|integer|min:1',
|
||||
'width' => 'required',
|
||||
'height' => 'required',
|
||||
'x' => 'required',
|
||||
'y' => 'required'
|
||||
'y' => 'required',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
@ -144,13 +140,13 @@ class StoryComposeController extends Controller
|
|||
|
||||
$story = Story::whereProfileId($user->profile_id)->findOrFail($id);
|
||||
|
||||
$path = storage_path('app/' . $story->path);
|
||||
$path = storage_path('app/'.$story->path);
|
||||
|
||||
if(!is_file($path)) {
|
||||
if (! is_file($path)) {
|
||||
abort(400, 'Invalid or missing media.');
|
||||
}
|
||||
|
||||
if($story->type === 'photo') {
|
||||
if ($story->type === 'photo') {
|
||||
$img = Intervention::make($path);
|
||||
$img->crop($width, $height, $x, $y);
|
||||
$img->resize(1080, 1920, function ($constraint) {
|
||||
|
@ -161,24 +157,24 @@ class StoryComposeController extends Controller
|
|||
|
||||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully cropped',
|
||||
'msg' => 'Successfully cropped',
|
||||
];
|
||||
}
|
||||
|
||||
public function publishStory(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'media_id' => 'required',
|
||||
'duration' => 'required|integer|min:3|max:120',
|
||||
'can_reply' => 'required|boolean',
|
||||
'can_react' => 'required|boolean'
|
||||
'can_react' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$id = $request->input('media_id');
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$story = Story::whereProfileId($user->profile_id)
|
||||
->findOrFail($id);
|
||||
|
||||
|
@ -194,13 +190,13 @@ class StoryComposeController extends Controller
|
|||
|
||||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully published',
|
||||
'msg' => 'Successfully published',
|
||||
];
|
||||
}
|
||||
|
||||
public function apiV1Delete(Request $request, $id)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
|
@ -213,40 +209,40 @@ class StoryComposeController extends Controller
|
|||
|
||||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully deleted'
|
||||
'msg' => 'Successfully deleted',
|
||||
];
|
||||
}
|
||||
|
||||
public function compose(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
return view('stories.compose');
|
||||
}
|
||||
|
||||
public function createPoll(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!config_cache('instance.polls.enabled'), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
abort_if(! config_cache('instance.polls.enabled'), 404);
|
||||
|
||||
return $request->all();
|
||||
}
|
||||
|
||||
public function publishStoryPoll(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'question' => 'required|string|min:6|max:140',
|
||||
'options' => 'required|array|min:2|max:4',
|
||||
'can_reply' => 'required|boolean',
|
||||
'can_react' => 'required|boolean'
|
||||
'can_react' => 'required|boolean',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$pid = $request->user()->profile_id;
|
||||
|
||||
$count = Story::whereProfileId($pid)
|
||||
|
@ -254,7 +250,7 @@ class StoryComposeController extends Controller
|
|||
->where('expires_at', '>', now())
|
||||
->count();
|
||||
|
||||
if($count >= Story::MAX_PER_DAY) {
|
||||
if ($count >= Story::MAX_PER_DAY) {
|
||||
abort(418, 'You have reached your limit for new Stories today.');
|
||||
}
|
||||
|
||||
|
@ -262,7 +258,7 @@ class StoryComposeController extends Controller
|
|||
$story->type = 'poll';
|
||||
$story->story = json_encode([
|
||||
'question' => $request->input('question'),
|
||||
'options' => $request->input('options')
|
||||
'options' => $request->input('options'),
|
||||
]);
|
||||
$story->public = false;
|
||||
$story->local = true;
|
||||
|
@ -278,7 +274,7 @@ class StoryComposeController extends Controller
|
|||
$poll->profile_id = $pid;
|
||||
$poll->poll_options = $request->input('options');
|
||||
$poll->expires_at = $story->expires_at;
|
||||
$poll->cached_tallies = collect($poll->poll_options)->map(function($o) {
|
||||
$poll->cached_tallies = collect($poll->poll_options)->map(function ($o) {
|
||||
return 0;
|
||||
})->toArray();
|
||||
$poll->save();
|
||||
|
@ -290,23 +286,23 @@ class StoryComposeController extends Controller
|
|||
|
||||
return [
|
||||
'code' => 200,
|
||||
'msg' => 'Successfully published',
|
||||
'msg' => 'Successfully published',
|
||||
];
|
||||
}
|
||||
|
||||
public function storyPollVote(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'sid' => 'required',
|
||||
'ci' => 'required|integer|min:0|max:3'
|
||||
'ci' => 'required|integer|min:0|max:3',
|
||||
]);
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
$ci = $request->input('ci');
|
||||
$story = Story::findOrFail($request->input('sid'));
|
||||
abort_if(!FollowerService::follows($pid, $story->profile_id), 403);
|
||||
abort_if(! FollowerService::follows($pid, $story->profile_id), 403);
|
||||
$poll = Poll::whereStoryId($story->id)->firstOrFail();
|
||||
|
||||
$vote = new PollVote;
|
||||
|
@ -318,7 +314,7 @@ class StoryComposeController extends Controller
|
|||
$vote->save();
|
||||
|
||||
$poll->votes_count = $poll->votes_count + 1;
|
||||
$poll->cached_tallies = collect($poll->getTallies())->map(function($tally, $key) use($ci) {
|
||||
$poll->cached_tallies = collect($poll->getTallies())->map(function ($tally, $key) use ($ci) {
|
||||
return $ci == $key ? $tally + 1 : $tally;
|
||||
})->toArray();
|
||||
$poll->save();
|
||||
|
@ -328,15 +324,15 @@ class StoryComposeController extends Controller
|
|||
|
||||
public function storeReport(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'type' => 'required|alpha_dash',
|
||||
'id' => 'required|integer|min:1',
|
||||
'type' => 'required|alpha_dash',
|
||||
'id' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
$sid = $request->input('id');
|
||||
|
@ -353,24 +349,24 @@ class StoryComposeController extends Controller
|
|||
'copyright',
|
||||
'impersonation',
|
||||
'scam',
|
||||
'terrorism'
|
||||
'terrorism',
|
||||
];
|
||||
|
||||
abort_if(!in_array($type, $types), 422, 'Invalid story report type');
|
||||
abort_if(! in_array($type, $types), 422, 'Invalid story report type');
|
||||
|
||||
$story = Story::findOrFail($sid);
|
||||
|
||||
abort_if($story->profile_id == $pid, 422, 'Cannot report your own story');
|
||||
abort_if(!FollowerService::follows($pid, $story->profile_id), 422, 'Cannot report a story from an account you do not follow');
|
||||
abort_if(! FollowerService::follows($pid, $story->profile_id), 422, 'Cannot report a story from an account you do not follow');
|
||||
|
||||
if( Report::whereProfileId($pid)
|
||||
if (Report::whereProfileId($pid)
|
||||
->whereObjectType('App\Story')
|
||||
->whereObjectId($story->id)
|
||||
->exists()
|
||||
) {
|
||||
return response()->json(['error' => [
|
||||
'code' => 409,
|
||||
'message' => 'Cannot report the same story again'
|
||||
'message' => 'Cannot report the same story again',
|
||||
]], 409);
|
||||
}
|
||||
|
||||
|
@ -389,18 +385,18 @@ class StoryComposeController extends Controller
|
|||
|
||||
public function react(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
$this->validate($request, [
|
||||
'sid' => 'required',
|
||||
'reaction' => 'required|string'
|
||||
'reaction' => 'required|string',
|
||||
]);
|
||||
$pid = $request->user()->profile_id;
|
||||
$text = $request->input('reaction');
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$story = Story::findOrFail($request->input('sid'));
|
||||
|
||||
abort_if(!$story->can_react, 422);
|
||||
abort_if(! $story->can_react, 422);
|
||||
abort_if(StoryService::reactCounter($story->id, $pid) >= 5, 422, 'You have already reacted to this story');
|
||||
|
||||
$status = new Status;
|
||||
|
@ -413,7 +409,7 @@ class StoryComposeController extends Controller
|
|||
$status->in_reply_to_profile_id = $story->profile_id;
|
||||
$status->entities = json_encode([
|
||||
'story_id' => $story->id,
|
||||
'reaction' => $text
|
||||
'reaction' => $text,
|
||||
]);
|
||||
$status->save();
|
||||
|
||||
|
@ -427,24 +423,24 @@ class StoryComposeController extends Controller
|
|||
'story_actor_username' => $request->user()->username,
|
||||
'story_id' => $story->id,
|
||||
'story_media_url' => url(Storage::url($story->path)),
|
||||
'reaction' => $text
|
||||
'reaction' => $text,
|
||||
]);
|
||||
$dm->save();
|
||||
|
||||
Conversation::updateOrInsert(
|
||||
[
|
||||
'to_id' => $story->profile_id,
|
||||
'from_id' => $pid
|
||||
'from_id' => $pid,
|
||||
],
|
||||
[
|
||||
'type' => 'story:react',
|
||||
'status_id' => $status->id,
|
||||
'dm_id' => $dm->id,
|
||||
'is_hidden' => false
|
||||
'is_hidden' => false,
|
||||
]
|
||||
);
|
||||
|
||||
if($story->local) {
|
||||
if ($story->local) {
|
||||
// generate notification
|
||||
$n = new Notification;
|
||||
$n->profile_id = $dm->to_id;
|
||||
|
@ -464,18 +460,18 @@ class StoryComposeController extends Controller
|
|||
|
||||
public function comment(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(! (bool) config_cache('instance.stories.enabled') || ! $request->user(), 404);
|
||||
$this->validate($request, [
|
||||
'sid' => 'required',
|
||||
'caption' => 'required|string'
|
||||
'caption' => 'required|string',
|
||||
]);
|
||||
$pid = $request->user()->profile_id;
|
||||
$text = $request->input('caption');
|
||||
$user = $request->user();
|
||||
abort_if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
abort_if($user->has_roles && ! UserRoleService::can('can-use-stories', $user->id), 403, 'Invalid permissions for this action');
|
||||
$story = Story::findOrFail($request->input('sid'));
|
||||
|
||||
abort_if(!$story->can_reply, 422);
|
||||
abort_if(! $story->can_reply, 422);
|
||||
|
||||
$status = new Status;
|
||||
$status->type = 'story:reply';
|
||||
|
@ -486,7 +482,7 @@ class StoryComposeController extends Controller
|
|||
$status->visibility = 'direct';
|
||||
$status->in_reply_to_profile_id = $story->profile_id;
|
||||
$status->entities = json_encode([
|
||||
'story_id' => $story->id
|
||||
'story_id' => $story->id,
|
||||
]);
|
||||
$status->save();
|
||||
|
||||
|
@ -500,24 +496,24 @@ class StoryComposeController extends Controller
|
|||
'story_actor_username' => $request->user()->username,
|
||||
'story_id' => $story->id,
|
||||
'story_media_url' => url(Storage::url($story->path)),
|
||||
'caption' => $text
|
||||
'caption' => $text,
|
||||
]);
|
||||
$dm->save();
|
||||
|
||||
Conversation::updateOrInsert(
|
||||
[
|
||||
'to_id' => $story->profile_id,
|
||||
'from_id' => $pid
|
||||
'from_id' => $pid,
|
||||
],
|
||||
[
|
||||
'type' => 'story:comment',
|
||||
'status_id' => $status->id,
|
||||
'dm_id' => $dm->id,
|
||||
'is_hidden' => false
|
||||
'is_hidden' => false,
|
||||
]
|
||||
);
|
||||
|
||||
if($story->local) {
|
||||
if ($story->local) {
|
||||
// generate notification
|
||||
$n = new Notification;
|
||||
$n->profile_id = $dm->to_id;
|
||||
|
|
|
@ -34,7 +34,7 @@ class StoryController extends StoryComposeController
|
|||
{
|
||||
public function recent(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
return [];
|
||||
|
@ -117,7 +117,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function profile(Request $request, $id)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
|
@ -176,7 +176,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function viewed(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'id' => 'required|min:1',
|
||||
|
@ -221,7 +221,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function exists(Request $request, $id)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
$user = $request->user();
|
||||
if($user->has_roles && !UserRoleService::can('can-use-stories', $user->id)) {
|
||||
return response()->json(false);
|
||||
|
@ -233,7 +233,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function iRedirect(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$user = $request->user();
|
||||
abort_if(!$user, 404);
|
||||
|
@ -243,7 +243,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function viewers(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'sid' => 'required|string'
|
||||
|
@ -274,7 +274,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function remoteStory(Request $request, $id)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$profile = Profile::findOrFail($id);
|
||||
if($profile->user_id != null || $profile->domain == null) {
|
||||
|
@ -286,7 +286,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function pollResults(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'sid' => 'required|string'
|
||||
|
@ -304,7 +304,7 @@ class StoryController extends StoryComposeController
|
|||
|
||||
public function getActivityObject(Request $request, $username, $id)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled'), 404);
|
||||
abort_if(!(bool) config_cache('instance.stories.enabled'), 404);
|
||||
|
||||
if(!$request->wantsJson()) {
|
||||
return redirect('/stories/' . $username);
|
||||
|
|
|
@ -34,7 +34,7 @@ class UserEmailForgotController extends Controller
|
|||
'username.exists' => 'This username is no longer active or does not exist!'
|
||||
];
|
||||
|
||||
if(config('captcha.enabled') || config('captcha.active.login') || config('captcha.active.register')) {
|
||||
if((bool) config_cache('captcha.enabled')) {
|
||||
$rules['h-captcha-response'] = 'required|captcha';
|
||||
$messages['h-captcha-response.required'] = 'You need to complete the captcha!';
|
||||
}
|
||||
|
|
|
@ -14,12 +14,12 @@ class Kernel extends HttpKernel
|
|||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Illuminate\Http\Middleware\HandleCors::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\ProfileMigration;
|
||||
use App\Services\FetchCacheService;
|
||||
use App\Services\WebfingerService;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class ProfileMigrationStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
if ((bool) config_cache('federation.activitypub.enabled') === false ||
|
||||
(bool) config_cache('federation.migration') === false) {
|
||||
return false;
|
||||
}
|
||||
if (! $this->user() || $this->user()->status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'acct' => 'required|email',
|
||||
'password' => 'required|current_password',
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
return [
|
||||
function (Validator $validator) {
|
||||
$err = $this->validateNewAccount();
|
||||
if ($err !== 'noerr') {
|
||||
$validator->errors()->add(
|
||||
'acct',
|
||||
$err
|
||||
);
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
protected function validateNewAccount()
|
||||
{
|
||||
if (ProfileMigration::whereProfileId($this->user()->profile_id)->where('created_at', '>', now()->subDays(30))->exists()) {
|
||||
return 'Error - You have migrated your account in the past 30 days, you can only perform a migration once per 30 days.';
|
||||
}
|
||||
$acct = WebfingerService::rawGet($this->acct);
|
||||
if (! $acct) {
|
||||
return 'The new account you provided is not responding to our requests.';
|
||||
}
|
||||
$pr = FetchCacheService::getJson($acct);
|
||||
if (! $pr || ! isset($pr['alsoKnownAs'])) {
|
||||
return 'Invalid account lookup response.';
|
||||
}
|
||||
if (! count($pr['alsoKnownAs']) || ! is_array($pr['alsoKnownAs'])) {
|
||||
return 'The new account does not contain an alias to your current account.';
|
||||
}
|
||||
$curAcctUrl = $this->user()->profile->permalink();
|
||||
if (! in_array($curAcctUrl, $pr['alsoKnownAs'])) {
|
||||
return 'The new account does not contain an alias to your current account.';
|
||||
}
|
||||
|
||||
return 'noerr';
|
||||
}
|
||||
}
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace App\Http\Requests\Status;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Media;
|
||||
use App\Status;
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreStatusEditRequest extends FormRequest
|
||||
{
|
||||
|
@ -14,24 +14,25 @@ class StoreStatusEditRequest extends FormRequest
|
|||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
$profile = $this->user()->profile;
|
||||
if($profile->status != null) {
|
||||
return false;
|
||||
}
|
||||
if($profile->unlisted == true && $profile->cw == true) {
|
||||
return false;
|
||||
}
|
||||
$types = [
|
||||
"photo",
|
||||
"photo:album",
|
||||
"photo:video:album",
|
||||
"reply",
|
||||
"text",
|
||||
"video",
|
||||
"video:album"
|
||||
];
|
||||
$scopes = ['public', 'unlisted', 'private'];
|
||||
$status = Status::whereNull('reblog_of_id')->whereIn('type', $types)->whereIn('scope', $scopes)->find($this->route('id'));
|
||||
$profile = $this->user()->profile;
|
||||
if ($profile->status != null) {
|
||||
return false;
|
||||
}
|
||||
if ($profile->unlisted == true && $profile->cw == true) {
|
||||
return false;
|
||||
}
|
||||
$types = [
|
||||
'photo',
|
||||
'photo:album',
|
||||
'photo:video:album',
|
||||
'reply',
|
||||
'text',
|
||||
'video',
|
||||
'video:album',
|
||||
];
|
||||
$scopes = ['public', 'unlisted', 'private'];
|
||||
$status = Status::whereNull('reblog_of_id')->whereIn('type', $types)->whereIn('scope', $scopes)->find($this->route('id'));
|
||||
|
||||
return $status && $this->user()->profile_id === $status->profile_id;
|
||||
}
|
||||
|
||||
|
@ -47,18 +48,18 @@ class StoreStatusEditRequest extends FormRequest
|
|||
'spoiler_text' => 'nullable|string|max:140',
|
||||
'sensitive' => 'sometimes|boolean',
|
||||
'media_ids' => [
|
||||
'nullable',
|
||||
'required_without:status',
|
||||
'array',
|
||||
'max:' . config('pixelfed.max_album_length'),
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
Media::whereProfileId($this->user()->profile_id)
|
||||
->where(function($query) {
|
||||
return $query->whereNull('status_id')
|
||||
->orWhere('status_id', '=', $this->route('id'));
|
||||
})
|
||||
->findOrFail($value);
|
||||
},
|
||||
'nullable',
|
||||
'required_without:status',
|
||||
'array',
|
||||
'max:'.(int) config_cache('pixelfed.max_album_length'),
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
Media::whereProfileId($this->user()->profile_id)
|
||||
->where(function ($query) {
|
||||
return $query->whereNull('status_id')
|
||||
->orWhere('status_id', '=', $this->route('id'));
|
||||
})
|
||||
->findOrFail($value);
|
||||
},
|
||||
],
|
||||
'location' => 'sometimes|nullable',
|
||||
'location.id' => 'sometimes|integer|min:1|max:128769',
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Instance;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\StatusService;
|
||||
|
||||
class AdminRemoteReport extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$instance = parse_url($this->uri, PHP_URL_HOST);
|
||||
$statuses = [];
|
||||
if($this->status_ids && count($this->status_ids)) {
|
||||
foreach($this->status_ids as $sid) {
|
||||
$s = StatusService::get($sid, false);
|
||||
if($s && $s['in_reply_to_id'] != null) {
|
||||
$parent = StatusService::get($s['in_reply_to_id'], false);
|
||||
if($parent) {
|
||||
$s['parent'] = $parent;
|
||||
}
|
||||
}
|
||||
if($s) {
|
||||
$statuses[] = $s;
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = [
|
||||
'id' => $this->id,
|
||||
'instance' => $instance,
|
||||
'reported' => AccountService::get($this->account_id, true),
|
||||
'status_ids' => $this->status_ids,
|
||||
'statuses' => $statuses,
|
||||
'message' => $this->comment,
|
||||
'report_meta' => $this->report_meta,
|
||||
'created_at' => optional($this->created_at)->format('c'),
|
||||
'action_taken_at' => optional($this->action_taken_at)->format('c'),
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
}
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace App\Jobs\AvatarPipeline;
|
||||
|
||||
use Cache;
|
||||
use App\Avatar;
|
||||
use App\Profile;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
@ -17,88 +17,88 @@ use Storage;
|
|||
|
||||
class AvatarOptimize implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $profile;
|
||||
protected $current;
|
||||
protected $profile;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
protected $current;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Profile $profile, $current)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->current = $current;
|
||||
}
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$avatar = $this->profile->avatar;
|
||||
$file = storage_path("app/$avatar->media_path");
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Profile $profile, $current)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->current = $current;
|
||||
}
|
||||
|
||||
try {
|
||||
$img = Intervention::make($file)->orientate();
|
||||
$img->fit(200, 200, function ($constraint) {
|
||||
$constraint->upsize();
|
||||
});
|
||||
$quality = config_cache('pixelfed.image_quality');
|
||||
$img->save($file, $quality);
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$avatar = $this->profile->avatar;
|
||||
$file = storage_path("app/$avatar->media_path");
|
||||
|
||||
$avatar = Avatar::whereProfileId($this->profile->id)->firstOrFail();
|
||||
$avatar->change_count = ++$avatar->change_count;
|
||||
$avatar->last_processed_at = Carbon::now();
|
||||
$avatar->save();
|
||||
Cache::forget('avatar:' . $avatar->profile_id);
|
||||
$this->deleteOldAvatar($avatar->media_path, $this->current);
|
||||
try {
|
||||
$img = Intervention::make($file)->orientate();
|
||||
$img->fit(200, 200, function ($constraint) {
|
||||
$constraint->upsize();
|
||||
});
|
||||
$quality = config_cache('pixelfed.image_quality');
|
||||
$img->save($file, $quality);
|
||||
|
||||
if(config_cache('pixelfed.cloud_storage') && config('instance.avatar.local_to_cloud')) {
|
||||
$this->uploadToCloud($avatar);
|
||||
} else {
|
||||
$avatar->cdn_url = null;
|
||||
$avatar->save();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
$avatar = Avatar::whereProfileId($this->profile->id)->firstOrFail();
|
||||
$avatar->change_count = ++$avatar->change_count;
|
||||
$avatar->last_processed_at = Carbon::now();
|
||||
$avatar->save();
|
||||
Cache::forget('avatar:'.$avatar->profile_id);
|
||||
$this->deleteOldAvatar($avatar->media_path, $this->current);
|
||||
|
||||
protected function deleteOldAvatar($new, $current)
|
||||
{
|
||||
if ( storage_path('app/'.$new) == $current ||
|
||||
Str::endsWith($current, 'avatars/default.png') ||
|
||||
Str::endsWith($current, 'avatars/default.jpg'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (is_file($current)) {
|
||||
@unlink($current);
|
||||
}
|
||||
}
|
||||
if ((bool) config_cache('pixelfed.cloud_storage') && (bool) config_cache('instance.avatar.local_to_cloud')) {
|
||||
$this->uploadToCloud($avatar);
|
||||
} else {
|
||||
$avatar->cdn_url = null;
|
||||
$avatar->save();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected function uploadToCloud($avatar)
|
||||
{
|
||||
$base = 'cache/avatars/' . $avatar->profile_id;
|
||||
$disk = Storage::disk(config('filesystems.cloud'));
|
||||
$disk->deleteDirectory($base);
|
||||
$path = $base . '/' . 'avatar_' . strtolower(Str::random(random_int(3,6))) . $avatar->change_count . '.' . pathinfo($avatar->media_path, PATHINFO_EXTENSION);
|
||||
$url = $disk->put($path, Storage::get($avatar->media_path));
|
||||
$avatar->media_path = $path;
|
||||
$avatar->cdn_url = $disk->url($path);
|
||||
$avatar->save();
|
||||
Storage::delete($avatar->media_path);
|
||||
Cache::forget('avatar:' . $avatar->profile_id);
|
||||
}
|
||||
protected function deleteOldAvatar($new, $current)
|
||||
{
|
||||
if (storage_path('app/'.$new) == $current ||
|
||||
Str::endsWith($current, 'avatars/default.png') ||
|
||||
Str::endsWith($current, 'avatars/default.jpg')) {
|
||||
return;
|
||||
}
|
||||
if (is_file($current)) {
|
||||
@unlink($current);
|
||||
}
|
||||
}
|
||||
|
||||
protected function uploadToCloud($avatar)
|
||||
{
|
||||
$base = 'cache/avatars/'.$avatar->profile_id;
|
||||
$disk = Storage::disk(config('filesystems.cloud'));
|
||||
$disk->deleteDirectory($base);
|
||||
$path = $base.'/'.'avatar_'.strtolower(Str::random(random_int(3, 6))).$avatar->change_count.'.'.pathinfo($avatar->media_path, PATHINFO_EXTENSION);
|
||||
$url = $disk->put($path, Storage::get($avatar->media_path));
|
||||
$avatar->media_path = $path;
|
||||
$avatar->cdn_url = $disk->url($path);
|
||||
$avatar->save();
|
||||
Storage::delete($avatar->media_path);
|
||||
Cache::forget('avatar:'.$avatar->profile_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,112 +4,107 @@ namespace App\Jobs\AvatarPipeline;
|
|||
|
||||
use App\Avatar;
|
||||
use App\Profile;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Illuminate\Support\Str;
|
||||
use Zttp\Zttp;
|
||||
use App\Http\Controllers\AvatarController;
|
||||
use Storage;
|
||||
use Log;
|
||||
use Illuminate\Http\File;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Services\ActivityPubFetchService;
|
||||
|
||||
class RemoteAvatarFetch implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $profile;
|
||||
protected $profile;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* The number of times the job may be attempted.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tries = 1;
|
||||
public $timeout = 300;
|
||||
public $maxExceptions = 1;
|
||||
/**
|
||||
* The number of times the job may be attempted.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tries = 1;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Profile $profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
}
|
||||
public $timeout = 300;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
public $maxExceptions = 1;
|
||||
|
||||
if(boolval(config_cache('pixelfed.cloud_storage')) == false && boolval(config_cache('federation.avatars.store_local')) == false) {
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Profile $profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
}
|
||||
|
||||
if($profile->domain == null || $profile->private_key) {
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
|
||||
$avatar = Avatar::whereProfileId($profile->id)->first();
|
||||
if ((bool) config_cache('pixelfed.cloud_storage') == false && (bool) config_cache('federation.avatars.store_local') == false) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!$avatar) {
|
||||
$avatar = new Avatar;
|
||||
$avatar->profile_id = $profile->id;
|
||||
$avatar->save();
|
||||
}
|
||||
if ($profile->domain == null || $profile->private_key) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if($avatar->media_path == null && $avatar->remote_url == null) {
|
||||
$avatar->media_path = 'public/avatars/default.jpg';
|
||||
$avatar->is_remote = true;
|
||||
$avatar->save();
|
||||
}
|
||||
$avatar = Avatar::whereProfileId($profile->id)->first();
|
||||
|
||||
$person = Helpers::fetchFromUrl($profile->remote_url);
|
||||
if (! $avatar) {
|
||||
$avatar = new Avatar;
|
||||
$avatar->profile_id = $profile->id;
|
||||
$avatar->save();
|
||||
}
|
||||
|
||||
if(!$person || !isset($person['@context'])) {
|
||||
return 1;
|
||||
}
|
||||
if ($avatar->media_path == null && $avatar->remote_url == null) {
|
||||
$avatar->media_path = 'public/avatars/default.jpg';
|
||||
$avatar->is_remote = true;
|
||||
$avatar->save();
|
||||
}
|
||||
|
||||
if( !isset($person['icon']) ||
|
||||
!isset($person['icon']['type']) ||
|
||||
!isset($person['icon']['url'])
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
$person = Helpers::fetchFromUrl($profile->remote_url);
|
||||
|
||||
if($person['icon']['type'] !== 'Image') {
|
||||
return 1;
|
||||
}
|
||||
if (! $person || ! isset($person['@context'])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!Helpers::validateUrl($person['icon']['url'])) {
|
||||
return 1;
|
||||
}
|
||||
if (! isset($person['icon']) ||
|
||||
! isset($person['icon']['type']) ||
|
||||
! isset($person['icon']['url'])
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$icon = $person['icon'];
|
||||
if ($person['icon']['type'] !== 'Image') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$avatar->remote_url = $icon['url'];
|
||||
$avatar->save();
|
||||
if (! Helpers::validateUrl($person['icon']['url'])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
MediaStorageService::avatar($avatar, boolval(config_cache('pixelfed.cloud_storage')) == false, true);
|
||||
$icon = $person['icon'];
|
||||
|
||||
return 1;
|
||||
}
|
||||
$avatar->remote_url = $icon['url'];
|
||||
$avatar->save();
|
||||
|
||||
MediaStorageService::avatar($avatar, (bool) config_cache('pixelfed.cloud_storage') == false, true);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,93 +4,88 @@ namespace App\Jobs\AvatarPipeline;
|
|||
|
||||
use App\Avatar;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\MediaStorageService;
|
||||
use Cache;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use Illuminate\Support\Str;
|
||||
use Zttp\Zttp;
|
||||
use App\Http\Controllers\AvatarController;
|
||||
use Cache;
|
||||
use Storage;
|
||||
use Log;
|
||||
use Illuminate\Http\File;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\MediaStorageService;
|
||||
use App\Services\ActivityPubFetchService;
|
||||
|
||||
class RemoteAvatarFetchFromUrl implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $profile;
|
||||
protected $url;
|
||||
protected $profile;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* The number of times the job may be attempted.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tries = 1;
|
||||
public $timeout = 300;
|
||||
public $maxExceptions = 1;
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Profile $profile, $url)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->url = $url;
|
||||
}
|
||||
/**
|
||||
* The number of times the job may be attempted.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tries = 1;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
public $timeout = 300;
|
||||
|
||||
Cache::forget('avatar:' . $profile->id);
|
||||
AccountService::del($profile->id);
|
||||
public $maxExceptions = 1;
|
||||
|
||||
if(boolval(config_cache('pixelfed.cloud_storage')) == false && boolval(config_cache('federation.avatars.store_local')) == false) {
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Profile $profile, $url)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
if($profile->domain == null || $profile->private_key) {
|
||||
return 1;
|
||||
}
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$profile = $this->profile;
|
||||
|
||||
$avatar = Avatar::whereProfileId($profile->id)->first();
|
||||
Cache::forget('avatar:'.$profile->id);
|
||||
AccountService::del($profile->id);
|
||||
|
||||
if(!$avatar) {
|
||||
$avatar = new Avatar;
|
||||
$avatar->profile_id = $profile->id;
|
||||
$avatar->is_remote = true;
|
||||
$avatar->remote_url = $this->url;
|
||||
$avatar->save();
|
||||
} else {
|
||||
$avatar->remote_url = $this->url;
|
||||
$avatar->is_remote = true;
|
||||
$avatar->save();
|
||||
}
|
||||
if ((bool) config_cache('pixelfed.cloud_storage') == false && (bool) config_cache('federation.avatars.store_local') == false) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
MediaStorageService::avatar($avatar, boolval(config_cache('pixelfed.cloud_storage')) == false, true);
|
||||
if ($profile->domain == null || $profile->private_key) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
$avatar = Avatar::whereProfileId($profile->id)->first();
|
||||
|
||||
if (! $avatar) {
|
||||
$avatar = new Avatar;
|
||||
$avatar->profile_id = $profile->id;
|
||||
$avatar->is_remote = true;
|
||||
$avatar->remote_url = $this->url;
|
||||
$avatar->save();
|
||||
} else {
|
||||
$avatar->remote_url = $this->url;
|
||||
$avatar->is_remote = true;
|
||||
$avatar->save();
|
||||
}
|
||||
|
||||
MediaStorageService::avatar($avatar, (bool) config_cache('pixelfed.cloud_storage') == false, true);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\CuratedOnboarding;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\CuratedRegister;
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Mail\CuratedRegisterNotifyAdmin;
|
||||
|
||||
class CuratedOnboardingNotifyAdminNewApplicationPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $cr;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(CuratedRegister $cr)
|
||||
{
|
||||
$this->cr = $cr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
if(!config('instance.curated_registration.notify.admin.on_verify_email.enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
config('instance.curated_registration.notify.admin.on_verify_email.bundle') ?
|
||||
$this->handleBundled() :
|
||||
$this->handleUnbundled();
|
||||
}
|
||||
|
||||
protected function handleBundled()
|
||||
{
|
||||
$cr = $this->cr;
|
||||
Storage::append('conanap.json', json_encode([
|
||||
'id' => $cr->id,
|
||||
'email' => $cr->email,
|
||||
'created_at' => $cr->created_at,
|
||||
'updated_at' => $cr->updated_at,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function handleUnbundled()
|
||||
{
|
||||
$cr = $this->cr;
|
||||
if($aid = config_cache('instance.admin.pid')) {
|
||||
$admin = User::whereProfileId($aid)->first();
|
||||
if($admin && $admin->email) {
|
||||
Mail::to($admin->email)->send(new CuratedRegisterNotifyAdmin($cr));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,114 +4,115 @@ namespace App\Jobs\FollowPipeline;
|
|||
|
||||
use App\Follower;
|
||||
use App\FollowRequest;
|
||||
use App\Jobs\HomeFeedPipeline\FeedUnfollowPipeline;
|
||||
use App\Notification;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\NotificationService;
|
||||
use Cache;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\Services\AccountService;
|
||||
use App\Services\FollowerService;
|
||||
use App\Services\NotificationService;
|
||||
use App\Jobs\HomeFeedPipeline\FeedUnfollowPipeline;
|
||||
|
||||
class UnfollowPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $actor;
|
||||
protected $target;
|
||||
protected $actor;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($actor, $target)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->target = $target;
|
||||
}
|
||||
protected $target;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$actor = $this->actor;
|
||||
$target = $this->target;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($actor, $target)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->target = $target;
|
||||
}
|
||||
|
||||
$actorProfile = Profile::find($actor);
|
||||
if(!$actorProfile) {
|
||||
return;
|
||||
}
|
||||
$targetProfile = Profile::find($target);
|
||||
if(!$targetProfile) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$actor = $this->actor;
|
||||
$target = $this->target;
|
||||
|
||||
FeedUnfollowPipeline::dispatch($actor, $target)->onQueue('follow');
|
||||
$actorProfile = Profile::find($actor);
|
||||
if (! $actorProfile) {
|
||||
return;
|
||||
}
|
||||
$targetProfile = Profile::find($target);
|
||||
if (! $targetProfile) {
|
||||
return;
|
||||
}
|
||||
|
||||
FollowerService::remove($actor, $target);
|
||||
FeedUnfollowPipeline::dispatch($actor, $target)->onQueue('follow');
|
||||
|
||||
$actorProfileSync = Cache::get(FollowerService::FOLLOWING_SYNC_KEY . $actor);
|
||||
if(!$actorProfileSync) {
|
||||
FollowServiceWarmCache::dispatch($actor)->onQueue('low');
|
||||
} else {
|
||||
if($actorProfile->following_count) {
|
||||
$actorProfile->decrement('following_count');
|
||||
} else {
|
||||
$count = Follower::whereProfileId($actor)->count();
|
||||
$actorProfile->following_count = $count;
|
||||
$actorProfile->save();
|
||||
}
|
||||
Cache::put(FollowerService::FOLLOWING_SYNC_KEY . $actor, 1, 604800);
|
||||
AccountService::del($actor);
|
||||
}
|
||||
FollowerService::remove($actor, $target);
|
||||
|
||||
$targetProfileSync = Cache::get(FollowerService::FOLLOWERS_SYNC_KEY . $target);
|
||||
if(!$targetProfileSync) {
|
||||
FollowServiceWarmCache::dispatch($target)->onQueue('low');
|
||||
} else {
|
||||
if($targetProfile->followers_count) {
|
||||
$targetProfile->decrement('followers_count');
|
||||
} else {
|
||||
$count = Follower::whereFollowingId($target)->count();
|
||||
$targetProfile->followers_count = $count;
|
||||
$targetProfile->save();
|
||||
}
|
||||
Cache::put(FollowerService::FOLLOWERS_SYNC_KEY . $target, 1, 604800);
|
||||
AccountService::del($target);
|
||||
}
|
||||
$actorProfileSync = Cache::get(FollowerService::FOLLOWING_SYNC_KEY.$actor);
|
||||
if (! $actorProfileSync) {
|
||||
FollowServiceWarmCache::dispatch($actor)->onQueue('low');
|
||||
} else {
|
||||
if ($actorProfile->following_count) {
|
||||
$actorProfile->decrement('following_count');
|
||||
} else {
|
||||
$count = Follower::whereProfileId($actor)->count();
|
||||
$actorProfile->following_count = $count;
|
||||
$actorProfile->save();
|
||||
}
|
||||
Cache::put(FollowerService::FOLLOWING_SYNC_KEY.$actor, 1, 604800);
|
||||
AccountService::del($actor);
|
||||
}
|
||||
|
||||
if($targetProfile->domain == null) {
|
||||
Notification::withTrashed()
|
||||
->whereProfileId($target)
|
||||
->whereAction('follow')
|
||||
->whereActorId($actor)
|
||||
->whereItemId($target)
|
||||
->whereItemType('App\Profile')
|
||||
->get()
|
||||
->each(function($n) {
|
||||
NotificationService::del($n->profile_id, $n->id);
|
||||
$n->forceDelete();
|
||||
});
|
||||
}
|
||||
$targetProfileSync = Cache::get(FollowerService::FOLLOWERS_SYNC_KEY.$target);
|
||||
if (! $targetProfileSync) {
|
||||
FollowServiceWarmCache::dispatch($target)->onQueue('low');
|
||||
} else {
|
||||
if ($targetProfile->followers_count) {
|
||||
$targetProfile->decrement('followers_count');
|
||||
} else {
|
||||
$count = Follower::whereFollowingId($target)->count();
|
||||
$targetProfile->followers_count = $count;
|
||||
$targetProfile->save();
|
||||
}
|
||||
Cache::put(FollowerService::FOLLOWERS_SYNC_KEY.$target, 1, 604800);
|
||||
AccountService::del($target);
|
||||
}
|
||||
|
||||
if($actorProfile->domain == null && config('instance.timeline.home.cached')) {
|
||||
Cache::forget('pf:timelines:home:' . $actor);
|
||||
}
|
||||
if ($targetProfile->domain == null) {
|
||||
Notification::withTrashed()
|
||||
->whereProfileId($target)
|
||||
->whereAction('follow')
|
||||
->whereActorId($actor)
|
||||
->whereItemId($target)
|
||||
->whereItemType('App\Profile')
|
||||
->get()
|
||||
->each(function ($n) {
|
||||
NotificationService::del($n->profile_id, $n->id);
|
||||
$n->forceDelete();
|
||||
});
|
||||
}
|
||||
|
||||
FollowRequest::whereFollowingId($target)
|
||||
->whereFollowerId($actor)
|
||||
->delete();
|
||||
if ($actorProfile->domain == null && config('instance.timeline.home.cached')) {
|
||||
Cache::forget('pf:timelines:home:'.$actor);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
FollowRequest::whereFollowingId($target)
|
||||
->whereFollowerId($actor)
|
||||
->delete();
|
||||
|
||||
AccountService::del($target);
|
||||
AccountService::del($actor);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class ImageOptimize implements ShouldQueue
|
|||
return;
|
||||
}
|
||||
|
||||
if(config('pixelfed.optimize_image') == false) {
|
||||
if((bool) config_cache('pixelfed.optimize_image') == false) {
|
||||
ImageThumbnail::dispatch($media)->onQueue('mmo');
|
||||
return;
|
||||
} else {
|
||||
|
|
|
@ -51,7 +51,7 @@ class ImageResize implements ShouldQueue
|
|||
return;
|
||||
}
|
||||
|
||||
if(!config('pixelfed.optimize_image')) {
|
||||
if((bool) config_cache('pixelfed.optimize_image') === false) {
|
||||
ImageThumbnail::dispatch($media)->onQueue('mmo');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ class ImageUpdate implements ShouldQueue
|
|||
return;
|
||||
}
|
||||
|
||||
if(config('pixelfed.optimize_image')) {
|
||||
if((bool) config_cache('pixelfed.optimize_image')) {
|
||||
if (in_array($media->mime, $this->protectedMimes) == true) {
|
||||
ImageOptimizer::optimize($thumb);
|
||||
if(!$media->skip_optimize) {
|
||||
|
|
|
@ -3,27 +3,30 @@
|
|||
namespace App\Jobs\MediaPipeline;
|
||||
|
||||
use App\Media;
|
||||
use App\Services\Media\MediaHlsService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Services\Media\MediaHlsService;
|
||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MediaDeletePipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
|
||||
class MediaDeletePipeline implements ShouldBeUniqueUntilProcessing, ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $media;
|
||||
protected $media;
|
||||
|
||||
public $timeout = 300;
|
||||
|
||||
public $tries = 3;
|
||||
|
||||
public $maxExceptions = 1;
|
||||
|
||||
public $failOnTimeout = true;
|
||||
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +41,7 @@ class MediaDeletePipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
|
|||
*/
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return 'media:purge-job:id-' . $this->media->id;
|
||||
return 'media:purge-job:id-'.$this->media->id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,58 +54,58 @@ class MediaDeletePipeline implements ShouldQueue, ShouldBeUniqueUntilProcessing
|
|||
return [(new WithoutOverlapping("media:purge-job:id-{$this->media->id}"))->shared()->dontRelease()];
|
||||
}
|
||||
|
||||
public function __construct(Media $media)
|
||||
{
|
||||
$this->media = $media;
|
||||
}
|
||||
public function __construct(Media $media)
|
||||
{
|
||||
$this->media = $media;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$media = $this->media;
|
||||
$path = $media->media_path;
|
||||
$thumb = $media->thumbnail_path;
|
||||
public function handle()
|
||||
{
|
||||
$media = $this->media;
|
||||
$path = $media->media_path;
|
||||
$thumb = $media->thumbnail_path;
|
||||
|
||||
if(!$path) {
|
||||
return 1;
|
||||
}
|
||||
if (! $path) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$e = explode('/', $path);
|
||||
array_pop($e);
|
||||
$i = implode('/', $e);
|
||||
$e = explode('/', $path);
|
||||
array_pop($e);
|
||||
$i = implode('/', $e);
|
||||
|
||||
if(config_cache('pixelfed.cloud_storage') == true) {
|
||||
$disk = Storage::disk(config('filesystems.cloud'));
|
||||
if ((bool) config_cache('pixelfed.cloud_storage') == true) {
|
||||
$disk = Storage::disk(config('filesystems.cloud'));
|
||||
|
||||
if($path && $disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
if ($path && $disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
if($thumb && $disk->exists($thumb)) {
|
||||
$disk->delete($thumb);
|
||||
}
|
||||
}
|
||||
if ($thumb && $disk->exists($thumb)) {
|
||||
$disk->delete($thumb);
|
||||
}
|
||||
}
|
||||
|
||||
$disk = Storage::disk(config('filesystems.local'));
|
||||
$disk = Storage::disk(config('filesystems.local'));
|
||||
|
||||
if($path && $disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
if ($path && $disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
if($thumb && $disk->exists($thumb)) {
|
||||
$disk->delete($thumb);
|
||||
}
|
||||
if ($thumb && $disk->exists($thumb)) {
|
||||
$disk->delete($thumb);
|
||||
}
|
||||
|
||||
if($media->hls_path != null) {
|
||||
if ($media->hls_path != null) {
|
||||
$files = MediaHlsService::allFiles($media);
|
||||
if($files && count($files)) {
|
||||
foreach($files as $file) {
|
||||
if ($files && count($files)) {
|
||||
foreach ($files as $file) {
|
||||
$disk->delete($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$media->delete();
|
||||
$media->delete();
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,68 +8,69 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MediaFixLocalFilesystemCleanupPipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 1800;
|
||||
public $tries = 5;
|
||||
public $maxExceptions = 1;
|
||||
public $timeout = 1800;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if(config_cache('pixelfed.cloud_storage') == false) {
|
||||
// Only run if cloud storage is enabled
|
||||
return;
|
||||
}
|
||||
public $tries = 5;
|
||||
|
||||
$disk = Storage::disk('local');
|
||||
$cloud = Storage::disk(config('filesystems.cloud'));
|
||||
public $maxExceptions = 1;
|
||||
|
||||
Media::whereNotNull(['status_id', 'cdn_url', 'replicated_at'])
|
||||
->chunk(20, function ($medias) use($disk, $cloud) {
|
||||
foreach($medias as $media) {
|
||||
if(!str_starts_with($media->media_path, 'public')) {
|
||||
continue;
|
||||
}
|
||||
public function handle()
|
||||
{
|
||||
if ((bool) config_cache('pixelfed.cloud_storage') == false) {
|
||||
// Only run if cloud storage is enabled
|
||||
return;
|
||||
}
|
||||
|
||||
if($disk->exists($media->media_path) && $cloud->exists($media->media_path)) {
|
||||
$disk->delete($media->media_path);
|
||||
}
|
||||
$disk = Storage::disk('local');
|
||||
$cloud = Storage::disk(config('filesystems.cloud'));
|
||||
|
||||
if($media->thumbnail_path) {
|
||||
if($disk->exists($media->thumbnail_path)) {
|
||||
$disk->delete($media->thumbnail_path);
|
||||
}
|
||||
}
|
||||
Media::whereNotNull(['status_id', 'cdn_url', 'replicated_at'])
|
||||
->chunk(20, function ($medias) use ($disk, $cloud) {
|
||||
foreach ($medias as $media) {
|
||||
if (! str_starts_with($media->media_path, 'public')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$paths = explode('/', $media->media_path);
|
||||
if(count($paths) === 7) {
|
||||
array_pop($paths);
|
||||
$baseDir = implode('/', $paths);
|
||||
if ($disk->exists($media->media_path) && $cloud->exists($media->media_path)) {
|
||||
$disk->delete($media->media_path);
|
||||
}
|
||||
|
||||
if(count($disk->allFiles($baseDir)) === 0) {
|
||||
$disk->deleteDirectory($baseDir);
|
||||
if ($media->thumbnail_path) {
|
||||
if ($disk->exists($media->thumbnail_path)) {
|
||||
$disk->delete($media->thumbnail_path);
|
||||
}
|
||||
}
|
||||
|
||||
array_pop($paths);
|
||||
$baseDir = implode('/', $paths);
|
||||
$paths = explode('/', $media->media_path);
|
||||
if (count($paths) === 7) {
|
||||
array_pop($paths);
|
||||
$baseDir = implode('/', $paths);
|
||||
|
||||
if(count($disk->allFiles($baseDir)) === 0) {
|
||||
$disk->deleteDirectory($baseDir);
|
||||
if (count($disk->allFiles($baseDir)) === 0) {
|
||||
$disk->deleteDirectory($baseDir);
|
||||
|
||||
array_pop($paths);
|
||||
$baseDir = implode('/', $paths);
|
||||
array_pop($paths);
|
||||
$baseDir = implode('/', $paths);
|
||||
|
||||
if(count($disk->allFiles($baseDir)) === 0) {
|
||||
$disk->deleteDirectory($baseDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (count($disk->allFiles($baseDir)) === 0) {
|
||||
$disk->deleteDirectory($baseDir);
|
||||
|
||||
array_pop($paths);
|
||||
$baseDir = implode('/', $paths);
|
||||
|
||||
if (count($disk->allFiles($baseDir)) === 0) {
|
||||
$disk->deleteDirectory($baseDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\ProfilePipeline;
|
||||
|
||||
use App\Transformer\ActivityPub\Verb\Move;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Pool;
|
||||
use Illuminate\Bus\Batchable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
|
||||
class ProfileMigrationDeliverMoveActivityPipeline implements ShouldBeUniqueUntilProcessing, ShouldQueue
|
||||
{
|
||||
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $migration;
|
||||
|
||||
public $oldAccount;
|
||||
|
||||
public $newAccount;
|
||||
|
||||
public $timeout = 1400;
|
||||
|
||||
public $tries = 3;
|
||||
|
||||
public $maxExceptions = 1;
|
||||
|
||||
public $failOnTimeout = true;
|
||||
|
||||
/**
|
||||
* The number of seconds after which the job's unique lock will be released.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $uniqueFor = 3600;
|
||||
|
||||
/**
|
||||
* Get the unique ID for the job.
|
||||
*/
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return 'profile:migration:deliver-move-followers:id:'.$this->migration->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
public function middleware(): array
|
||||
{
|
||||
return [(new WithoutOverlapping('profile:migration:deliver-move-followers:id:'.$this->migration->id))->shared()->dontRelease()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($migration, $oldAccount, $newAccount)
|
||||
{
|
||||
$this->migration = $migration;
|
||||
$this->oldAccount = $oldAccount;
|
||||
$this->newAccount = $newAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->batch()->cancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$migration = $this->migration;
|
||||
$profile = $this->oldAccount;
|
||||
$newAccount = $this->newAccount;
|
||||
|
||||
if ($profile->domain || ! $profile->private_key) {
|
||||
return;
|
||||
}
|
||||
|
||||
$audience = $profile->getAudienceInbox();
|
||||
$activitypubObject = new Move();
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($migration, $activitypubObject);
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
|
||||
$payload = json_encode($activity);
|
||||
|
||||
$client = new Client([
|
||||
'timeout' => config('federation.activitypub.delivery.timeout'),
|
||||
]);
|
||||
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
|
||||
$requests = function ($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach ($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function () use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_SSL_VERIFYHOST => false,
|
||||
],
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
},
|
||||
]);
|
||||
|
||||
$promise = $pool->promise();
|
||||
|
||||
$promise->wait();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs\ProfilePipeline;
|
||||
|
||||
use App\Follower;
|
||||
use App\Profile;
|
||||
use App\Services\AccountService;
|
||||
use Illuminate\Bus\Batchable;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ProfileMigrationMoveFollowersPipeline implements ShouldBeUniqueUntilProcessing, ShouldQueue
|
||||
{
|
||||
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $oldPid;
|
||||
|
||||
public $newPid;
|
||||
|
||||
public $timeout = 1400;
|
||||
|
||||
public $tries = 3;
|
||||
|
||||
public $maxExceptions = 1;
|
||||
|
||||
public $failOnTimeout = true;
|
||||
|
||||
/**
|
||||
* The number of seconds after which the job's unique lock will be released.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $uniqueFor = 3600;
|
||||
|
||||
/**
|
||||
* Get the unique ID for the job.
|
||||
*/
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return 'profile:migration:move-followers:oldpid-'.$this->oldPid.':newpid-'.$this->newPid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the middleware the job should pass through.
|
||||
*
|
||||
* @return array<int, object>
|
||||
*/
|
||||
public function middleware(): array
|
||||
{
|
||||
return [(new WithoutOverlapping('profile:migration:move-followers:oldpid-'.$this->oldPid.':newpid-'.$this->newPid))->shared()->dontRelease()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($oldPid, $newPid)
|
||||
{
|
||||
$this->oldPid = $oldPid;
|
||||
$this->newPid = $newPid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
if ($this->batch()->cancelled()) {
|
||||
return;
|
||||
}
|
||||
$og = Profile::find($this->oldPid);
|
||||
$ne = Profile::find($this->newPid);
|
||||
if (! $og || ! $ne || $og == $ne) {
|
||||
return;
|
||||
}
|
||||
$ne->followers_count = $og->followers_count;
|
||||
$ne->save();
|
||||
$og->followers_count = 0;
|
||||
$og->save();
|
||||
foreach (Follower::whereFollowingId($this->oldPid)->lazyById(200, 'id') as $follower) {
|
||||
try {
|
||||
$follower->following_id = $this->newPid;
|
||||
$follower->save();
|
||||
} catch (Exception $e) {
|
||||
$follower->delete();
|
||||
}
|
||||
}
|
||||
AccountService::del($this->oldPid);
|
||||
AccountService::del($this->newPid);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ use Log;
|
|||
use Storage;
|
||||
use Zttp\Zttp;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Services\MediaPathService;
|
||||
|
||||
class RemoteFollowImportRecent implements ShouldQueue
|
||||
{
|
||||
|
@ -45,7 +46,6 @@ class RemoteFollowImportRecent implements ShouldQueue
|
|||
'image/jpg',
|
||||
'image/jpeg',
|
||||
'image/png',
|
||||
'image/gif',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -208,9 +208,7 @@ class RemoteFollowImportRecent implements ShouldQueue
|
|||
public function importMedia($url, $mime, $status)
|
||||
{
|
||||
$user = $this->profile;
|
||||
$monthHash = hash('sha1', date('Y').date('m'));
|
||||
$userHash = hash('sha1', $user->id.(string) $user->created_at);
|
||||
$storagePath = "public/m/{$monthHash}/{$userHash}";
|
||||
$storagePath = MediaPathService::get($user, 2);
|
||||
|
||||
try {
|
||||
$info = pathinfo($url);
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
|
||||
namespace App\Jobs\SharePipeline;
|
||||
|
||||
use Cache, Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\{Status, Notification};
|
||||
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
|
||||
use App\Notification;
|
||||
use App\Services\ReblogService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\Transformer\ActivityPub\Verb\Announce;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Pool;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
@ -12,141 +18,136 @@ use Illuminate\Queue\InteractsWithQueue;
|
|||
use Illuminate\Queue\SerializesModels;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use App\Transformer\ActivityPub\Verb\Announce;
|
||||
use GuzzleHttp\{Pool, Client, Promise};
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use App\Services\ReblogService;
|
||||
use App\Services\StatusService;
|
||||
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
|
||||
|
||||
class SharePipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $status;
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$status = $this->status;
|
||||
$parent = Status::find($this->status->reblog_of_id);
|
||||
if(!$parent) {
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$status = $this->status;
|
||||
$parent = Status::find($this->status->reblog_of_id);
|
||||
if (! $parent) {
|
||||
return;
|
||||
}
|
||||
$actor = $status->profile;
|
||||
$target = $parent->profile;
|
||||
$actor = $status->profile;
|
||||
$target = $parent->profile;
|
||||
|
||||
if ($status->uri !== null) {
|
||||
// Ignore notifications to remote statuses
|
||||
return;
|
||||
}
|
||||
if ($status->uri !== null) {
|
||||
// Ignore notifications to remote statuses
|
||||
return;
|
||||
}
|
||||
|
||||
if($target->id === $status->profile_id) {
|
||||
$this->remoteAnnounceDeliver();
|
||||
return true;
|
||||
}
|
||||
if ($target->id === $status->profile_id) {
|
||||
$this->remoteAnnounceDeliver();
|
||||
|
||||
ReblogService::addPostReblog($parent->profile_id, $status->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
$parent->reblogs_count = $parent->reblogs_count + 1;
|
||||
$parent->save();
|
||||
StatusService::del($parent->id);
|
||||
ReblogService::addPostReblog($parent->profile_id, $status->id);
|
||||
|
||||
Notification::firstOrCreate(
|
||||
[
|
||||
'profile_id' => $target->id,
|
||||
'actor_id' => $actor->id,
|
||||
'action' => 'share',
|
||||
'item_type' => 'App\Status',
|
||||
'item_id' => $status->reblog_of_id ?? $status->id,
|
||||
]
|
||||
);
|
||||
$parent->reblogs_count = $parent->reblogs_count + 1;
|
||||
$parent->save();
|
||||
StatusService::del($parent->id);
|
||||
|
||||
FeedInsertPipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
|
||||
Notification::firstOrCreate(
|
||||
[
|
||||
'profile_id' => $target->id,
|
||||
'actor_id' => $actor->id,
|
||||
'action' => 'share',
|
||||
'item_type' => 'App\Status',
|
||||
'item_id' => $status->reblog_of_id ?? $status->id,
|
||||
]
|
||||
);
|
||||
|
||||
return $this->remoteAnnounceDeliver();
|
||||
}
|
||||
FeedInsertPipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
|
||||
|
||||
public function remoteAnnounceDeliver()
|
||||
{
|
||||
if(config('app.env') !== 'production' || config_cache('federation.activitypub.enabled') == false) {
|
||||
return true;
|
||||
}
|
||||
$status = $this->status;
|
||||
$profile = $status->profile;
|
||||
return $this->remoteAnnounceDeliver();
|
||||
}
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($status, new Announce());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
public function remoteAnnounceDeliver()
|
||||
{
|
||||
if (config('app.env') !== 'production' || (bool) config_cache('federation.activitypub.enabled') == false) {
|
||||
return true;
|
||||
}
|
||||
$status = $this->status;
|
||||
$profile = $status->profile;
|
||||
|
||||
$audience = $status->profile->getAudienceInbox();
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($status, new Announce());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
|
||||
if(empty($audience) || $status->scope != 'public') {
|
||||
// Return on profiles with no remote followers
|
||||
return;
|
||||
}
|
||||
$audience = $status->profile->getAudienceInbox();
|
||||
|
||||
$payload = json_encode($activity);
|
||||
if (empty($audience) || $status->scope != 'public') {
|
||||
// Return on profiles with no remote followers
|
||||
return;
|
||||
}
|
||||
|
||||
$client = new Client([
|
||||
'timeout' => config('federation.activitypub.delivery.timeout')
|
||||
]);
|
||||
$payload = json_encode($activity);
|
||||
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
$client = new Client([
|
||||
'timeout' => config('federation.activitypub.delivery.timeout'),
|
||||
]);
|
||||
|
||||
$requests = function($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function() use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true
|
||||
]
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
}
|
||||
]);
|
||||
$requests = function ($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach ($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function () use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true,
|
||||
],
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$promise = $pool->promise();
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
},
|
||||
]);
|
||||
|
||||
$promise->wait();
|
||||
$promise = $pool->promise();
|
||||
|
||||
}
|
||||
$promise->wait();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,15 @@
|
|||
|
||||
namespace App\Jobs\SharePipeline;
|
||||
|
||||
use Cache, Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use App\{Status, Notification};
|
||||
use App\Jobs\HomeFeedPipeline\FeedRemovePipeline;
|
||||
use App\Notification;
|
||||
use App\Services\ReblogService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\Transformer\ActivityPub\Verb\UndoAnnounce;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Pool;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
|
@ -12,128 +18,125 @@ use Illuminate\Queue\InteractsWithQueue;
|
|||
use Illuminate\Queue\SerializesModels;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use App\Transformer\ActivityPub\Verb\UndoAnnounce;
|
||||
use GuzzleHttp\{Pool, Client, Promise};
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use App\Services\ReblogService;
|
||||
use App\Services\StatusService;
|
||||
use App\Jobs\HomeFeedPipeline\FeedRemovePipeline;
|
||||
|
||||
class UndoSharePipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $status;
|
||||
public $deleteWhenMissingModels = true;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
protected $status;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$status = $this->status;
|
||||
$actor = $status->profile;
|
||||
$parent = Status::find($status->reblog_of_id);
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
FeedRemovePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
if($parent) {
|
||||
$target = $parent->profile_id;
|
||||
ReblogService::removePostReblog($parent->profile_id, $status->id);
|
||||
public function handle()
|
||||
{
|
||||
$status = $this->status;
|
||||
$actor = $status->profile;
|
||||
$parent = Status::find($status->reblog_of_id);
|
||||
|
||||
if($parent->reblogs_count > 0) {
|
||||
$parent->reblogs_count = $parent->reblogs_count - 1;
|
||||
$parent->save();
|
||||
StatusService::del($parent->id);
|
||||
}
|
||||
FeedRemovePipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
|
||||
|
||||
$notification = Notification::whereProfileId($target)
|
||||
->whereActorId($status->profile_id)
|
||||
->whereAction('share')
|
||||
->whereItemId($status->reblog_of_id)
|
||||
->whereItemType('App\Status')
|
||||
->first();
|
||||
if ($parent) {
|
||||
$target = $parent->profile_id;
|
||||
ReblogService::removePostReblog($parent->profile_id, $status->id);
|
||||
|
||||
if($notification) {
|
||||
$notification->forceDelete();
|
||||
}
|
||||
}
|
||||
if ($parent->reblogs_count > 0) {
|
||||
$parent->reblogs_count = $parent->reblogs_count - 1;
|
||||
$parent->save();
|
||||
StatusService::del($parent->id);
|
||||
}
|
||||
|
||||
if ($status->uri != null) {
|
||||
return;
|
||||
}
|
||||
$notification = Notification::whereProfileId($target)
|
||||
->whereActorId($status->profile_id)
|
||||
->whereAction('share')
|
||||
->whereItemId($status->reblog_of_id)
|
||||
->whereItemType('App\Status')
|
||||
->first();
|
||||
|
||||
if(config('app.env') !== 'production' || config_cache('federation.activitypub.enabled') == false) {
|
||||
return $status->delete();
|
||||
} else {
|
||||
return $this->remoteAnnounceDeliver();
|
||||
}
|
||||
}
|
||||
if ($notification) {
|
||||
$notification->forceDelete();
|
||||
}
|
||||
}
|
||||
|
||||
public function remoteAnnounceDeliver()
|
||||
{
|
||||
if(config('app.env') !== 'production' || config_cache('federation.activitypub.enabled') == false) {
|
||||
if ($status->uri != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config('app.env') !== 'production' || (bool) config_cache('federation.activitypub.enabled') == false) {
|
||||
return $status->delete();
|
||||
} else {
|
||||
return $this->remoteAnnounceDeliver();
|
||||
}
|
||||
}
|
||||
|
||||
public function remoteAnnounceDeliver()
|
||||
{
|
||||
if (config('app.env') !== 'production' || (bool) config_cache('federation.activitypub.enabled') == false) {
|
||||
$status->delete();
|
||||
return 1;
|
||||
}
|
||||
|
||||
$status = $this->status;
|
||||
$profile = $status->profile;
|
||||
return 1;
|
||||
}
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($status, new UndoAnnounce());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
$status = $this->status;
|
||||
$profile = $status->profile;
|
||||
|
||||
$audience = $status->profile->getAudienceInbox();
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($status, new UndoAnnounce());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
|
||||
if(empty($audience) || $status->scope != 'public') {
|
||||
return 1;
|
||||
}
|
||||
$audience = $status->profile->getAudienceInbox();
|
||||
|
||||
$payload = json_encode($activity);
|
||||
if (empty($audience) || $status->scope != 'public') {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$client = new Client([
|
||||
'timeout' => config('federation.activitypub.delivery.timeout')
|
||||
]);
|
||||
$payload = json_encode($activity);
|
||||
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
$client = new Client([
|
||||
'timeout' => config('federation.activitypub.delivery.timeout'),
|
||||
]);
|
||||
|
||||
$requests = function($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function() use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true
|
||||
]
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
}
|
||||
]);
|
||||
$requests = function ($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach ($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function () use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true,
|
||||
],
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$promise = $pool->promise();
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
},
|
||||
]);
|
||||
|
||||
$promise->wait();
|
||||
$promise = $pool->promise();
|
||||
|
||||
$status->delete();
|
||||
$promise->wait();
|
||||
|
||||
return 1;
|
||||
}
|
||||
$status->delete();
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,126 +2,122 @@
|
|||
|
||||
namespace App\Jobs\StatusPipeline;
|
||||
|
||||
use DB, Cache, Storage;
|
||||
use App\{
|
||||
AccountInterstitial,
|
||||
Bookmark,
|
||||
CollectionItem,
|
||||
DirectMessage,
|
||||
Like,
|
||||
Media,
|
||||
MediaTag,
|
||||
Mention,
|
||||
Notification,
|
||||
Report,
|
||||
Status,
|
||||
StatusArchived,
|
||||
StatusHashtag,
|
||||
StatusView
|
||||
};
|
||||
use App\AccountInterstitial;
|
||||
use App\Bookmark;
|
||||
use App\CollectionItem;
|
||||
use App\DirectMessage;
|
||||
use App\Jobs\MediaPipeline\MediaDeletePipeline;
|
||||
use App\Like;
|
||||
use App\Media;
|
||||
use App\MediaTag;
|
||||
use App\Mention;
|
||||
use App\Notification;
|
||||
use App\Report;
|
||||
use App\Services\CollectionService;
|
||||
use App\Services\NotificationService;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use App\StatusArchived;
|
||||
use App\StatusHashtag;
|
||||
use App\StatusView;
|
||||
use App\Transformer\ActivityPub\Verb\DeleteNote;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use Cache;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Pool;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use League\Fractal;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use App\Transformer\ActivityPub\Verb\DeleteNote;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use GuzzleHttp\Pool;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Promise;
|
||||
use App\Util\ActivityPub\HttpSignature;
|
||||
use App\Services\CollectionService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\NotificationService;
|
||||
use App\Jobs\MediaPipeline\MediaDeletePipeline;
|
||||
|
||||
class StatusDelete implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $status;
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
/**
|
||||
* Delete the job if its models no longer exist.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $deleteWhenMissingModels = true;
|
||||
|
||||
public $timeout = 900;
|
||||
|
||||
public $tries = 2;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$status = $this->status;
|
||||
$profile = $this->status->profile;
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$status = $this->status;
|
||||
$profile = $this->status->profile;
|
||||
|
||||
StatusService::del($status->id, true);
|
||||
if($profile) {
|
||||
if(in_array($status->type, ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) {
|
||||
$profile->status_count = $profile->status_count - 1;
|
||||
$profile->save();
|
||||
}
|
||||
}
|
||||
StatusService::del($status->id, true);
|
||||
if ($profile) {
|
||||
if (in_array($status->type, ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) {
|
||||
$profile->status_count = $profile->status_count - 1;
|
||||
$profile->save();
|
||||
}
|
||||
}
|
||||
|
||||
Cache::forget('pf:atom:user-feed:by-id:' . $status->profile_id);
|
||||
Cache::forget('pf:atom:user-feed:by-id:'.$status->profile_id);
|
||||
|
||||
if(config_cache('federation.activitypub.enabled') == true) {
|
||||
return $this->fanoutDelete($status);
|
||||
} else {
|
||||
return $this->unlinkRemoveMedia($status);
|
||||
}
|
||||
}
|
||||
if ((bool) config_cache('federation.activitypub.enabled') == true) {
|
||||
return $this->fanoutDelete($status);
|
||||
} else {
|
||||
return $this->unlinkRemoveMedia($status);
|
||||
}
|
||||
}
|
||||
|
||||
public function unlinkRemoveMedia($status)
|
||||
{
|
||||
public function unlinkRemoveMedia($status)
|
||||
{
|
||||
Media::whereStatusId($status->id)
|
||||
->get()
|
||||
->each(function($media) {
|
||||
MediaDeletePipeline::dispatch($media);
|
||||
});
|
||||
->get()
|
||||
->each(function ($media) {
|
||||
MediaDeletePipeline::dispatch($media);
|
||||
});
|
||||
|
||||
if($status->in_reply_to_id) {
|
||||
$parent = Status::findOrFail($status->in_reply_to_id);
|
||||
--$parent->reply_count;
|
||||
$parent->save();
|
||||
StatusService::del($parent->id);
|
||||
}
|
||||
if ($status->in_reply_to_id) {
|
||||
$parent = Status::findOrFail($status->in_reply_to_id);
|
||||
$parent->reply_count--;
|
||||
$parent->save();
|
||||
StatusService::del($parent->id);
|
||||
}
|
||||
|
||||
Bookmark::whereStatusId($status->id)->delete();
|
||||
|
||||
CollectionItem::whereObjectType('App\Status')
|
||||
->whereObjectId($status->id)
|
||||
->get()
|
||||
->each(function($col) {
|
||||
->each(function ($col) {
|
||||
CollectionService::removeItem($col->collection_id, $col->object_id);
|
||||
$col->delete();
|
||||
});
|
||||
});
|
||||
|
||||
$dms = DirectMessage::whereStatusId($status->id)->get();
|
||||
foreach($dms as $dm) {
|
||||
foreach ($dms as $dm) {
|
||||
$not = Notification::whereItemType('App\DirectMessage')
|
||||
->whereItemId($dm->id)
|
||||
->first();
|
||||
if($not) {
|
||||
if ($not) {
|
||||
NotificationService::del($not->profile_id, $not->id);
|
||||
$not->forceDeleteQuietly();
|
||||
}
|
||||
|
@ -130,11 +126,11 @@ class StatusDelete implements ShouldQueue
|
|||
Like::whereStatusId($status->id)->delete();
|
||||
|
||||
$mediaTags = MediaTag::where('status_id', $status->id)->get();
|
||||
foreach($mediaTags as $mtag) {
|
||||
foreach ($mediaTags as $mtag) {
|
||||
$not = Notification::whereItemType('App\MediaTag')
|
||||
->whereItemId($mtag->id)
|
||||
->first();
|
||||
if($not) {
|
||||
if ($not) {
|
||||
NotificationService::del($not->profile_id, $not->id);
|
||||
$not->forceDeleteQuietly();
|
||||
}
|
||||
|
@ -142,85 +138,85 @@ class StatusDelete implements ShouldQueue
|
|||
}
|
||||
Mention::whereStatusId($status->id)->forceDelete();
|
||||
|
||||
Notification::whereItemType('App\Status')
|
||||
->whereItemId($status->id)
|
||||
->forceDelete();
|
||||
Notification::whereItemType('App\Status')
|
||||
->whereItemId($status->id)
|
||||
->forceDelete();
|
||||
|
||||
Report::whereObjectType('App\Status')
|
||||
->whereObjectId($status->id)
|
||||
->delete();
|
||||
Report::whereObjectType('App\Status')
|
||||
->whereObjectId($status->id)
|
||||
->delete();
|
||||
|
||||
StatusArchived::whereStatusId($status->id)->delete();
|
||||
StatusHashtag::whereStatusId($status->id)->delete();
|
||||
StatusView::whereStatusId($status->id)->delete();
|
||||
Status::whereInReplyToId($status->id)->update(['in_reply_to_id' => null]);
|
||||
Status::whereInReplyToId($status->id)->update(['in_reply_to_id' => null]);
|
||||
|
||||
AccountInterstitial::where('item_type', 'App\Status')
|
||||
->where('item_id', $status->id)
|
||||
->delete();
|
||||
AccountInterstitial::where('item_type', 'App\Status')
|
||||
->where('item_id', $status->id)
|
||||
->delete();
|
||||
|
||||
$status->delete();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function fanoutDelete($status)
|
||||
{
|
||||
$profile = $status->profile;
|
||||
|
||||
if(!$profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
$audience = $status->profile->getAudienceInbox();
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($status, new DeleteNote());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
|
||||
$this->unlinkRemoveMedia($status);
|
||||
|
||||
$payload = json_encode($activity);
|
||||
|
||||
$client = new Client([
|
||||
'timeout' => config('federation.activitypub.delivery.timeout')
|
||||
]);
|
||||
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
|
||||
$requests = function($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function() use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true
|
||||
]
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
}
|
||||
]);
|
||||
|
||||
$promise = $pool->promise();
|
||||
|
||||
$promise->wait();
|
||||
$status->delete();
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public function fanoutDelete($status)
|
||||
{
|
||||
$profile = $status->profile;
|
||||
|
||||
if (! $profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
$audience = $status->profile->getAudienceInbox();
|
||||
|
||||
$fractal = new Fractal\Manager();
|
||||
$fractal->setSerializer(new ArraySerializer());
|
||||
$resource = new Fractal\Resource\Item($status, new DeleteNote());
|
||||
$activity = $fractal->createData($resource)->toArray();
|
||||
|
||||
$this->unlinkRemoveMedia($status);
|
||||
|
||||
$payload = json_encode($activity);
|
||||
|
||||
$client = new Client([
|
||||
'timeout' => config('federation.activitypub.delivery.timeout'),
|
||||
]);
|
||||
|
||||
$version = config('pixelfed.version');
|
||||
$appUrl = config('app.url');
|
||||
$userAgent = "(Pixelfed/{$version}; +{$appUrl})";
|
||||
|
||||
$requests = function ($audience) use ($client, $activity, $profile, $payload, $userAgent) {
|
||||
foreach ($audience as $url) {
|
||||
$headers = HttpSignature::sign($profile, $url, $activity, [
|
||||
'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
||||
'User-Agent' => $userAgent,
|
||||
]);
|
||||
yield function () use ($client, $url, $headers, $payload) {
|
||||
return $client->postAsync($url, [
|
||||
'curl' => [
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_POSTFIELDS => $payload,
|
||||
CURLOPT_HEADER => true,
|
||||
],
|
||||
]);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
$pool = new Pool($client, $requests($audience), [
|
||||
'concurrency' => config('federation.activitypub.delivery.concurrency'),
|
||||
'fulfilled' => function ($response, $index) {
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
},
|
||||
]);
|
||||
|
||||
$promise = $pool->promise();
|
||||
|
||||
$promise->wait();
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,16 @@
|
|||
namespace App\Jobs\StatusPipeline;
|
||||
|
||||
use App\Hashtag;
|
||||
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
|
||||
use App\Jobs\MentionPipeline\MentionPipeline;
|
||||
use App\Mention;
|
||||
use App\Profile;
|
||||
use App\Services\AdminShadowFilterService;
|
||||
use App\Services\PublicTimelineService;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\UserFilterService;
|
||||
use App\Status;
|
||||
use App\StatusHashtag;
|
||||
use App\Services\PublicTimelineService;
|
||||
use App\Util\Lexer\Autolink;
|
||||
use App\Util\Lexer\Extractor;
|
||||
use App\Util\Sentiment\Bouncer;
|
||||
|
@ -19,18 +23,15 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Services\StatusService;
|
||||
use App\Services\UserFilterService;
|
||||
use App\Services\AdminShadowFilterService;
|
||||
use App\Jobs\HomeFeedPipeline\FeedInsertPipeline;
|
||||
use App\Jobs\HomeFeedPipeline\HashtagInsertFanoutPipeline;
|
||||
|
||||
class StatusEntityLexer implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $status;
|
||||
|
||||
protected $entities;
|
||||
|
||||
protected $autolink;
|
||||
|
||||
/**
|
||||
|
@ -60,12 +61,12 @@ class StatusEntityLexer implements ShouldQueue
|
|||
$profile = $this->status->profile;
|
||||
$status = $this->status;
|
||||
|
||||
if(in_array($status->type, ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) {
|
||||
if (in_array($status->type, ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])) {
|
||||
$profile->status_count = $profile->status_count + 1;
|
||||
$profile->save();
|
||||
}
|
||||
|
||||
if($profile->no_autolink == false) {
|
||||
if ($profile->no_autolink == false) {
|
||||
$this->parseEntities();
|
||||
}
|
||||
}
|
||||
|
@ -103,16 +104,16 @@ class StatusEntityLexer implements ShouldQueue
|
|||
$status = $this->status;
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if(mb_strlen($tag) > 124) {
|
||||
if (mb_strlen($tag) > 124) {
|
||||
continue;
|
||||
}
|
||||
DB::transaction(function () use ($status, $tag) {
|
||||
$slug = str_slug($tag, '-', false);
|
||||
|
||||
$hashtag = Hashtag::firstOrCreate([
|
||||
'slug' => $slug
|
||||
'slug' => $slug,
|
||||
], [
|
||||
'name' => $tag
|
||||
'name' => $tag,
|
||||
]);
|
||||
|
||||
StatusHashtag::firstOrCreate(
|
||||
|
@ -136,11 +137,11 @@ class StatusEntityLexer implements ShouldQueue
|
|||
foreach ($mentions as $mention) {
|
||||
$mentioned = Profile::whereUsername($mention)->first();
|
||||
|
||||
if (empty($mentioned) || !isset($mentioned->id)) {
|
||||
if (empty($mentioned) || ! isset($mentioned->id)) {
|
||||
continue;
|
||||
}
|
||||
$blocks = UserFilterService::blocks($mentioned->id);
|
||||
if($blocks && in_array($status->profile_id, $blocks)) {
|
||||
if ($blocks && in_array($status->profile_id, $blocks)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -161,8 +162,8 @@ class StatusEntityLexer implements ShouldQueue
|
|||
$status = $this->status;
|
||||
StatusService::refresh($status->id);
|
||||
|
||||
if(config('exp.cached_home_timeline')) {
|
||||
if( $status->in_reply_to_id === null &&
|
||||
if (config('exp.cached_home_timeline')) {
|
||||
if ($status->in_reply_to_id === null &&
|
||||
in_array($status->scope, ['public', 'unlisted', 'private'])
|
||||
) {
|
||||
FeedInsertPipeline::dispatch($status->id, $status->profile_id)->onQueue('feed');
|
||||
|
@ -179,28 +180,28 @@ class StatusEntityLexer implements ShouldQueue
|
|||
'photo:album',
|
||||
'video',
|
||||
'video:album',
|
||||
'photo:video:album'
|
||||
'photo:video:album',
|
||||
];
|
||||
|
||||
if(config_cache('pixelfed.bouncer.enabled')) {
|
||||
if ((bool) config_cache('pixelfed.bouncer.enabled')) {
|
||||
Bouncer::get($status);
|
||||
}
|
||||
|
||||
Cache::forget('pf:atom:user-feed:by-id:' . $status->profile_id);
|
||||
Cache::forget('pf:atom:user-feed:by-id:'.$status->profile_id);
|
||||
$hideNsfw = config('instance.hide_nsfw_on_public_feeds');
|
||||
if( $status->uri == null &&
|
||||
if ($status->uri == null &&
|
||||
$status->scope == 'public' &&
|
||||
in_array($status->type, $types) &&
|
||||
$status->in_reply_to_id === null &&
|
||||
$status->reblog_of_id === null &&
|
||||
($hideNsfw ? $status->is_nsfw == false : true)
|
||||
) {
|
||||
if(AdminShadowFilterService::canAddToPublicFeedByProfileId($status->profile_id)) {
|
||||
if (AdminShadowFilterService::canAddToPublicFeedByProfileId($status->profile_id)) {
|
||||
PublicTimelineService::add($status->id);
|
||||
}
|
||||
}
|
||||
|
||||
if(config_cache('federation.activitypub.enabled') == true && config('app.env') == 'production') {
|
||||
if ((bool) config_cache('federation.activitypub.enabled') == true && config('app.env') == 'production') {
|
||||
StatusActivityPubDeliver::dispatch($status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,172 +2,171 @@
|
|||
|
||||
namespace App\Jobs\StatusPipeline;
|
||||
|
||||
use App\Media;
|
||||
use App\Models\StatusEdit;
|
||||
use App\ModLog;
|
||||
use App\Profile;
|
||||
use App\Services\StatusService;
|
||||
use App\Status;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Media;
|
||||
use App\ModLog;
|
||||
use App\Profile;
|
||||
use App\Status;
|
||||
use App\Models\StatusEdit;
|
||||
use App\Services\StatusService;
|
||||
use Purify;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Purify;
|
||||
|
||||
class StatusRemoteUpdatePipeline implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $activity;
|
||||
public $activity;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($activity)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
}
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct($activity)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$activity = $this->activity;
|
||||
$status = Status::with('media')->whereObjectUrl($activity['id'])->first();
|
||||
if(!$status) {
|
||||
return;
|
||||
}
|
||||
$this->createPreviousEdit($status);
|
||||
$this->updateMedia($status, $activity);
|
||||
$this->updateImmediateAttributes($status, $activity);
|
||||
$this->createEdit($status, $activity);
|
||||
}
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$activity = $this->activity;
|
||||
$status = Status::with('media')->whereObjectUrl($activity['id'])->first();
|
||||
if (! $status) {
|
||||
return;
|
||||
}
|
||||
$this->createPreviousEdit($status);
|
||||
$this->updateMedia($status, $activity);
|
||||
$this->updateImmediateAttributes($status, $activity);
|
||||
$this->createEdit($status, $activity);
|
||||
}
|
||||
|
||||
protected function createPreviousEdit($status)
|
||||
{
|
||||
if(!$status->edits()->count()) {
|
||||
StatusEdit::create([
|
||||
'status_id' => $status->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
'caption' => $status->caption,
|
||||
'spoiler_text' => $status->cw_summary,
|
||||
'is_nsfw' => $status->is_nsfw,
|
||||
'ordered_media_attachment_ids' => $status->media()->orderBy('order')->pluck('id')->toArray(),
|
||||
'created_at' => $status->created_at
|
||||
]);
|
||||
}
|
||||
}
|
||||
protected function createPreviousEdit($status)
|
||||
{
|
||||
if (! $status->edits()->count()) {
|
||||
StatusEdit::create([
|
||||
'status_id' => $status->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
'caption' => $status->caption,
|
||||
'spoiler_text' => $status->cw_summary,
|
||||
'is_nsfw' => $status->is_nsfw,
|
||||
'ordered_media_attachment_ids' => $status->media()->orderBy('order')->pluck('id')->toArray(),
|
||||
'created_at' => $status->created_at,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function updateMedia($status, $activity)
|
||||
{
|
||||
if(!isset($activity['attachment'])) {
|
||||
return;
|
||||
}
|
||||
$ogm = $status->media->count() ? $status->media()->orderBy('order')->get() : collect([]);
|
||||
$nm = collect($activity['attachment'])->filter(function($nm) {
|
||||
return isset(
|
||||
$nm['type'],
|
||||
$nm['mediaType'],
|
||||
$nm['url']
|
||||
) &&
|
||||
in_array($nm['type'], ['Document', 'Image', 'Video']) &&
|
||||
in_array($nm['mediaType'], explode(',', config('pixelfed.media_types')));
|
||||
});
|
||||
protected function updateMedia($status, $activity)
|
||||
{
|
||||
if (! isset($activity['attachment'])) {
|
||||
return;
|
||||
}
|
||||
$ogm = $status->media->count() ? $status->media()->orderBy('order')->get() : collect([]);
|
||||
$nm = collect($activity['attachment'])->filter(function ($nm) {
|
||||
return isset(
|
||||
$nm['type'],
|
||||
$nm['mediaType'],
|
||||
$nm['url']
|
||||
) &&
|
||||
in_array($nm['type'], ['Document', 'Image', 'Video']) &&
|
||||
in_array($nm['mediaType'], explode(',', config_cache('pixelfed.media_types')));
|
||||
});
|
||||
|
||||
// Skip when no media
|
||||
if(!$ogm->count() && !$nm->count()) {
|
||||
return;
|
||||
}
|
||||
// Skip when no media
|
||||
if (! $ogm->count() && ! $nm->count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Media::whereProfileId($status->profile_id)
|
||||
->whereStatusId($status->id)
|
||||
->update([
|
||||
'status_id' => null
|
||||
]);
|
||||
Media::whereProfileId($status->profile_id)
|
||||
->whereStatusId($status->id)
|
||||
->update([
|
||||
'status_id' => null,
|
||||
]);
|
||||
|
||||
$nm->each(function($n, $key) use($status) {
|
||||
$res = Http::withOptions(['allow_redirects' => false])->retry(3, 100, throw: false)->head($n['url']);
|
||||
$nm->each(function ($n, $key) use ($status) {
|
||||
$res = Http::withOptions(['allow_redirects' => false])->retry(3, 100, throw: false)->head($n['url']);
|
||||
|
||||
if(!$res->successful()) {
|
||||
return;
|
||||
}
|
||||
if (! $res->successful()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!in_array($res->header('content-type'), explode(',',config('pixelfed.media_types')))) {
|
||||
return;
|
||||
}
|
||||
if (! in_array($res->header('content-type'), explode(',', config_cache('pixelfed.media_types')))) {
|
||||
return;
|
||||
}
|
||||
|
||||
$m = new Media;
|
||||
$m->status_id = $status->id;
|
||||
$m->profile_id = $status->profile_id;
|
||||
$m->remote_media = true;
|
||||
$m->media_path = $n['url'];
|
||||
$m = new Media;
|
||||
$m->status_id = $status->id;
|
||||
$m->profile_id = $status->profile_id;
|
||||
$m->remote_media = true;
|
||||
$m->media_path = $n['url'];
|
||||
$m->mime = $res->header('content-type');
|
||||
$m->size = $res->hasHeader('content-length') ? $res->header('content-length') : null;
|
||||
$m->caption = isset($n['name']) && !empty($n['name']) ? Purify::clean($n['name']) : null;
|
||||
$m->remote_url = $n['url'];
|
||||
$m->caption = isset($n['name']) && ! empty($n['name']) ? Purify::clean($n['name']) : null;
|
||||
$m->remote_url = $n['url'];
|
||||
$m->blurhash = isset($n['blurhash']) && (strlen($n['blurhash']) < 50) ? $n['blurhash'] : null;
|
||||
$m->width = isset($n['width']) && !empty($n['width']) ? $n['width'] : null;
|
||||
$m->height = isset($n['height']) && !empty($n['height']) ? $n['height'] : null;
|
||||
$m->skip_optimize = true;
|
||||
$m->order = $key + 1;
|
||||
$m->save();
|
||||
});
|
||||
}
|
||||
$m->width = isset($n['width']) && ! empty($n['width']) ? $n['width'] : null;
|
||||
$m->height = isset($n['height']) && ! empty($n['height']) ? $n['height'] : null;
|
||||
$m->skip_optimize = true;
|
||||
$m->order = $key + 1;
|
||||
$m->save();
|
||||
});
|
||||
}
|
||||
|
||||
protected function updateImmediateAttributes($status, $activity)
|
||||
{
|
||||
if(isset($activity['content'])) {
|
||||
$status->caption = strip_tags($activity['content']);
|
||||
$status->rendered = Purify::clean($activity['content']);
|
||||
}
|
||||
protected function updateImmediateAttributes($status, $activity)
|
||||
{
|
||||
if (isset($activity['content'])) {
|
||||
$status->caption = strip_tags($activity['content']);
|
||||
$status->rendered = Purify::clean($activity['content']);
|
||||
}
|
||||
|
||||
if(isset($activity['sensitive'])) {
|
||||
if((bool) $activity['sensitive'] == false) {
|
||||
$status->is_nsfw = false;
|
||||
$exists = ModLog::whereObjectType('App\Status::class')
|
||||
->whereObjectId($status->id)
|
||||
->whereAction('admin.status.moderate')
|
||||
->exists();
|
||||
if($exists == true) {
|
||||
$status->is_nsfw = true;
|
||||
}
|
||||
$profile = Profile::find($status->profile_id);
|
||||
if(!$profile || $profile->cw == true) {
|
||||
$status->is_nsfw = true;
|
||||
}
|
||||
} else {
|
||||
$status->is_nsfw = true;
|
||||
}
|
||||
}
|
||||
if (isset($activity['sensitive'])) {
|
||||
if ((bool) $activity['sensitive'] == false) {
|
||||
$status->is_nsfw = false;
|
||||
$exists = ModLog::whereObjectType('App\Status::class')
|
||||
->whereObjectId($status->id)
|
||||
->whereAction('admin.status.moderate')
|
||||
->exists();
|
||||
if ($exists == true) {
|
||||
$status->is_nsfw = true;
|
||||
}
|
||||
$profile = Profile::find($status->profile_id);
|
||||
if (! $profile || $profile->cw == true) {
|
||||
$status->is_nsfw = true;
|
||||
}
|
||||
} else {
|
||||
$status->is_nsfw = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($activity['summary'])) {
|
||||
$status->cw_summary = Purify::clean($activity['summary']);
|
||||
} else {
|
||||
$status->cw_summary = null;
|
||||
}
|
||||
if (isset($activity['summary'])) {
|
||||
$status->cw_summary = Purify::clean($activity['summary']);
|
||||
} else {
|
||||
$status->cw_summary = null;
|
||||
}
|
||||
|
||||
$status->edited_at = now();
|
||||
$status->save();
|
||||
StatusService::del($status->id);
|
||||
}
|
||||
$status->edited_at = now();
|
||||
$status->save();
|
||||
StatusService::del($status->id);
|
||||
}
|
||||
|
||||
protected function createEdit($status, $activity)
|
||||
{
|
||||
$cleaned = isset($activity['content']) ? Purify::clean($activity['content']) : null;
|
||||
$spoiler_text = isset($activity['summary']) ? Purify::clean($activity['summary']) : null;
|
||||
$sensitive = isset($activity['sensitive']) ? $activity['sensitive'] : null;
|
||||
$mids = $status->media()->count() ? $status->media()->orderBy('order')->pluck('id')->toArray() : null;
|
||||
StatusEdit::create([
|
||||
'status_id' => $status->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
'caption' => $cleaned,
|
||||
'spoiler_text' => $spoiler_text,
|
||||
'is_nsfw' => $sensitive,
|
||||
'ordered_media_attachment_ids' => $mids
|
||||
]);
|
||||
}
|
||||
protected function createEdit($status, $activity)
|
||||
{
|
||||
$cleaned = isset($activity['content']) ? Purify::clean($activity['content']) : null;
|
||||
$spoiler_text = isset($activity['summary']) ? Purify::clean($activity['summary']) : null;
|
||||
$sensitive = isset($activity['sensitive']) ? $activity['sensitive'] : null;
|
||||
$mids = $status->media()->count() ? $status->media()->orderBy('order')->pluck('id')->toArray() : null;
|
||||
StatusEdit::create([
|
||||
'status_id' => $status->id,
|
||||
'profile_id' => $status->profile_id,
|
||||
'caption' => $cleaned,
|
||||
'spoiler_text' => $spoiler_text,
|
||||
'is_nsfw' => $sensitive,
|
||||
'ordered_media_attachment_ids' => $mids,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ class Like extends Model
|
|||
{
|
||||
use SoftDeletes;
|
||||
|
||||
const MAX_PER_DAY = 500;
|
||||
const MAX_PER_DAY = 1500;
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CuratedRegisterAcceptUser extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $verify;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct($verify)
|
||||
{
|
||||
$this->verify = $verify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Your ' . config('pixelfed.domain.app') . ' Registration Update',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.curated-register.request-accepted',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\CuratedRegister;
|
||||
|
||||
class CuratedRegisterConfirmEmail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
public $verify;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(CuratedRegister $verify)
|
||||
{
|
||||
$this->verify = $verify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Welcome to Pixelfed! Please Confirm Your Email',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.curated-register.confirm_email',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\CuratedRegister;
|
||||
|
||||
class CuratedRegisterNotifyAdmin extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
public $verify;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(CuratedRegister $verify)
|
||||
{
|
||||
$this->verify = $verify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '[Requires Action]: New Curated Onboarding Application',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.curated-register.admin_notify',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CuratedRegisterNotifyAdminUserResponse extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $activity;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct($activity)
|
||||
{
|
||||
$this->activity = $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Curated Register Notify Admin User Response',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.curated-register.admin_notify_user_response',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CuratedRegisterRejectUser extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $verify;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct($verify)
|
||||
{
|
||||
$this->verify = $verify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Your ' . config('pixelfed.domain.app') . ' Registration Update',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.curated-register.request-rejected',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\CuratedRegister;
|
||||
use App\Models\CuratedRegisterActivity;
|
||||
|
||||
class CuratedRegisterRequestDetailsFromUser extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
public $verify;
|
||||
public $activity;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct(CuratedRegister $verify, CuratedRegisterActivity $activity)
|
||||
{
|
||||
$this->verify = $verify;
|
||||
$this->activity = $activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: '[Action Needed]: Additional information requested',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.curated-register.request-details-from-user',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CuratedRegisterSendMessage extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public $verify;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*/
|
||||
public function __construct($verify)
|
||||
{
|
||||
$this->verify = $verify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message envelope.
|
||||
*/
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
return new Envelope(
|
||||
subject: 'Your ' . config('pixelfed.domain.app') . ' Registration Update',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the message content definition.
|
||||
*/
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: 'emails.curated-register.message-from-admin',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attachments for the message.
|
||||
*
|
||||
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||
*/
|
||||
public function attachments(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -8,8 +8,14 @@ class MediaTag extends Model
|
|||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $visible = [
|
||||
'status_id',
|
||||
'profile_id',
|
||||
'tagged_username',
|
||||
];
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo(Status::class);
|
||||
return $this->belongsTo(Status::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CuratedRegister extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_has_responded'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'autofollow_account_ids' => 'array',
|
||||
'admin_notes' => 'array',
|
||||
'email_verified_at' => 'datetime',
|
||||
'admin_notified_at' => 'datetime',
|
||||
'action_taken_at' => 'datetime',
|
||||
'user_has_responded' => 'boolean',
|
||||
'is_awaiting_more_info' => 'boolean',
|
||||
'is_accepted' => 'boolean',
|
||||
'is_rejected' => 'boolean',
|
||||
'is_closed' => 'boolean',
|
||||
];
|
||||
|
||||
public function adminStatusLabel()
|
||||
{
|
||||
if($this->user_has_responded) {
|
||||
return '<span class="border border-warning px-3 py-1 rounded text-white font-weight-bold">Awaiting Admin Response</span>';
|
||||
}
|
||||
if(!$this->email_verified_at) {
|
||||
return '<span class="border border-danger px-3 py-1 rounded text-white font-weight-bold">Unverified email</span>';
|
||||
}
|
||||
if($this->is_approved) {
|
||||
return '<span class="badge badge-success bg-success text-dark">Approved</span>';
|
||||
}
|
||||
if($this->is_rejected) {
|
||||
return '<span class="badge badge-danger bg-danger text-white">Rejected</span>';
|
||||
}
|
||||
if($this->is_awaiting_more_info ) {
|
||||
return '<span class="border border-info px-3 py-1 rounded text-white font-weight-bold">Awaiting User Response</span>';
|
||||
}
|
||||
if($this->is_closed ) {
|
||||
return '<span class="border border-muted px-3 py-1 rounded text-white font-weight-bold" style="opacity:0.5">Closed</span>';
|
||||
}
|
||||
|
||||
return '<span class="border border-success px-3 py-1 rounded text-white font-weight-bold">Open</span>';
|
||||
}
|
||||
|
||||
public function emailConfirmUrl()
|
||||
{
|
||||
return url('/auth/sign_up/confirm?sid=' . $this->id . '&code=' . $this->verify_code);
|
||||
}
|
||||
|
||||
public function emailReplyUrl()
|
||||
{
|
||||
return url('/auth/sign_up/concierge?sid=' . $this->id . '&code=' . $this->verify_code . '&sc=' . str_random(8));
|
||||
}
|
||||
|
||||
public function adminReviewUrl()
|
||||
{
|
||||
return url('/i/admin/curated-onboarding/show/' . $this->id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CuratedRegisterActivity extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
'admin_notified_at' => 'datetime',
|
||||
'action_taken_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function application()
|
||||
{
|
||||
return $this->belongsTo(CuratedRegister::class, 'register_id');
|
||||
}
|
||||
|
||||
public function emailReplyUrl()
|
||||
{
|
||||
return url('/auth/sign_up/concierge?sid='.$this->register_id . '&id=' . $this->id . '&code=' . $this->secret_code);
|
||||
}
|
||||
|
||||
public function adminReviewUrl()
|
||||
{
|
||||
$url = '/i/admin/curated-onboarding/show/' . $this->register_id . '/?ah=' . $this->id;
|
||||
if($this->reply_to_id) {
|
||||
$url .= '&rtid=' . $this->reply_to_id;
|
||||
}
|
||||
return url($url);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Ładowanie…
Reference in New Issue