🖼 Simple file viewer with slideshow for media
Перейти к файлу
hamza221 eb17ef910d
fix 404 on blank.mp4
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
2023-05-24 06:22:37 +02:00
.github feat: add bundle size analyzer 2023-05-23 15:12:26 +02:00
.tx [tx-robot] Update transifex configuration 2022-10-01 03:06:13 +00:00
appinfo feat(deps): Add Nextcloud 28 support on master 2023-05-17 15:25:06 +02:00
composer Add composer autoloader 2023-02-20 11:22:35 +01:00
cypress Cypress - update another base image (focus ring) 2023-04-28 23:32:10 +02:00
img fix 404 on blank.mp4 2023-05-24 06:22:37 +02:00
js fix 404 on blank.mp4 2023-05-24 06:22:37 +02:00
l10n Fix(l10n): Update translations from Transifex 2023-05-22 01:35:52 +00:00
lib Update php styling for 7.4 2022-04-09 17:17:38 +02:00
src fix 404 on blank.mp4 2023-05-24 06:22:37 +02:00
tests Create psalm.yml 2022-10-02 12:37:17 +02:00
.editorconfig Viewer first commit 2019-02-21 21:45:35 +01:00
.eslintrc.js Comply to new addScript API 2021-12-01 17:47:11 +00:00
.gitattributes Remove ie and last 2 versions 2021-02-22 10:09:11 +01:00
.gitignore feat: add bundle size analyzer 2023-05-23 15:12:26 +02:00
.l10nignore Update .l10nignore to exclude bundled JS files 2020-09-15 12:34:31 +02:00
.npmignore Viewer first commit 2019-02-21 21:45:35 +01:00
.php-cs-fixer.dist.php Add composer autoloader 2023-02-20 11:22:35 +01:00
.stylelintignore Bump deps and audit fix 2022-01-04 07:26:06 +01:00
COPYING Viewer first commit 2019-02-21 21:45:35 +01:00
README.md Note about cypress tests in README 2023-05-11 21:40:24 +02:00
babel.config.js Fix bundles 2021-07-26 21:56:17 +02:00
composer.json Add composer autoloader 2023-02-20 11:22:35 +01:00
composer.lock Chore(deps-dev): Bump phpunit/phpunit from 9.6.7 to 9.6.8 2023-05-13 01:56:30 +00:00
cypress.config.ts Chore(deps-dev): Bump cypress-visual-regression from 2.1.1 to 3.0.0 2023-04-26 14:18:08 +02:00
package-lock.json adjust versions 2023-05-17 16:19:09 +02:00
package.json feat: add bundle size analyzer 2023-05-23 15:12:26 +02:00
psalm.xml Update psalm.xml 2022-10-02 14:34:06 +02:00
stylelint.config.js Update and simplify plyr theme 2022-08-23 11:34:49 +02:00
test.txt Edit test commit 2022-10-13 11:08:53 +02:00
tsconfig.json Chore(deps-dev): Bump cypress-visual-regression from 2.1.1 to 3.0.0 2023-04-26 14:18:08 +02:00
webpack.config.ts Adapt cypress tests 2022-10-25 18:58:38 +02:00

README.md

Files viewer for nextcloud

Show your latest holiday photos and videos like in the movies. Show a glimpse of your latest novel directly from your nextcloud. Choose the best GIF of your collection thanks to the direct view of your favorites files!

viewer

📋 Current support

  • Images
  • Videos

🏗 Development setup

  1. ☁ Clone this app into the apps folder of your Nextcloud: git clone https://github.com/nextcloud/viewer.git
  2. 👩‍💻 In the folder of the app, install dependencies with npm ci and build the Javascript with npm run build.
  3. Enable the app through the app management of your Nextcloud
  4. 🎉 Partytime!

🧙 Advanced development stuff

To build the Javascript whenever you make changes, you can also run npm run dev for development builds.

📷 Running cypress tests

To run e2e cypress tests, execute npm run cypress.

The visual-regression tests require additional care as they depend on installation of fonts in the application. To achieve repeatable results run the tests using npm run cypress:visual-regression. This will build the app with the required fonts and run the tests.

If changes are required to the reference (base) screenshots used by the visual-regression tests, run cypress:update-snapshots and commit the updated screenshots.

API

Add the viewer to your app

In php, on your page, emit the LoadViewer event. Check the documentation/tutorial for more info on this type of page controller sample.

use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;

class PageController extends Controller {
	protected $appName;

	/** @var IEventDispatcher */
	private $eventDispatcher;

	public function __construct($appName,
								IRequest $request,
								IEventDispatcher $eventDispatcher) {
		parent::__construct($appName, $request);

		$this->appName = $appName;
		$this->eventDispatcher = $eventDispatcher;
	}

	/**
	 * @NoAdminRequired
	 * @NoCSRFRequired
	 * Render default index template
	 *
	 * @return TemplateResponse
	 */
	public function index(): TemplateResponse {
		$this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer());
		$response = new TemplateResponse($this->appName, 'main');
		return $response;
	}
}

This will load all the necessary scripts and make the Viewer accessible trough javascript at OCA.Viewer

Open a file

  1. Open a file on WebDAV and let the viewer fetch the folder data
OCA.Viewer.open({path: '/path/to/file.jpg'})
  1. Open a file on WebDAV and provide a list of files
OCA.Viewer.open({
  	path: '/path/to/file.jpg',
  	list: [
  		{
  			basename: 'file.jpg',
  			filename: '/path/to/file.jpg',
  			...
  		},
  		...
  	],
})
// Alternative: pass known file info so it doesn't need to be fetched
const fileInfo = {
  filename: '/path/to/file.jpg',
  basename: 'file.jpg',
  mime: 'image/jpeg',
  etag: 'xyz987',
  hasPreview: true,
  fileid: 13579,
}
OCA.Viewer.open({
  fileinfo: fileInfo,
  list: [fileInfo],
})

The list parameter requires an array of fileinfo. You can check how we generate a fileinfo object here from a dav PROPFIND request data. There is currently no dedicated package for it, but this is coming. You can check the photos repository where we also use it.

  1. Open a file from an app's route
const fileInfo1 = {
  filename: 'https://next.cloud/apps/pizza/topping/pineapple.jpg',
  basename: 'pineapple.jpg',
  source: 'https://next.cloud/apps/pizza/topping/pineapple.jpg',
  mime: 'image/jpeg',
  etag: 'abc123',
  hasPreview: false,
  fileid: 12345,
}
const fileInfo2 = {
  filename: 'https://next.cloud/apps/pizza/topping/garlic.jpg',
  basename: 'garlic.jpg',
  source: 'https://next.cloud/apps/pizza/topping/garlic.jpg',
  mime: 'image/jpeg',
  etag: 'def456',
  hasPreview: false,
  fileid: 67890,
}
OCA.Viewer.open({
  fileInfo: fileInfo1,
  list: [fileInfo1, fileInfo2],
})

In order to open a shared file you will need to provide the share token so the Viewer can use it to authenticate the requests to the server. See the files_sharing app controller and template for an example.

Close the viewer

OCA.Viewer.close()

🔍 Add you own file view

If you want to make your app compatible with this app, you can use the OCA.Viewer methods

  1. Create a vue component which use the path and mime props (they will be automatically passed by the viewer)
  2. Register your mime viewer with the following:
     import VideoView from 'VideoView.vue'
    
     OCA.Viewer.registerHandler({
         // unique id
         id: 'video',
    
        // optional, it will group every view of this group and
        // use the proper view when building the file list
        // of the slideshow.
        // e.g. you open an image/jpeg that have the `media` group
        // you will be able to see the video/mpeg from the `video` handler
        // files that also have the `media` group set.
        group: 'media',
    
        // the list of mimes your component is able to display
        mimes: [
             'video/mpeg',
             'video/ogg',
             'video/webm',
             'video/mp4'
         ],
    
         // your vue component view
         component: VideoView
     })
    
  3. if you feel like your mime should be integrated on this repo, you can also create a pull request with your object on the models directory and the view on the components directory. Please have a look at what's already here and take example of it. 🙇‍♀️