NHFinder
NHFinder is a simple photo manager. Can integrate with CKEditor (has been customized).
Files
Source includes:
- build-inline: The custom ckeditor set can be integrated with NHFinder.
- nodejs: Back-end of NHFinder
- reactjs: Front-end of NHFinder
Install
yarn add @ngochipx/nhfinder
Using
- Create file config/nhfinder.js for the backend.
module.exports = {
ROOTDIR: __ROOTDIR__,
UPLOAD_PATH: __ROOTDIR__ + '/public/uploads/',
PUBLIC_PATH: '/uploads',
DOMAIN: 'http://localhost:3000',
ALLOW_EXTENSIONS: ['.jpg','.jpeg', '.png', '.bmp', '.gif','.txt'],
API_KEY: "123456"
};
- In the routes file of the backend (use express). Add:
...
const nhfinderConfig = require('config/nhfinder.js')
const nhfinderRoutes = require('@ngochipx/nhfinder/nodejs/routes')(nhfinderConfig)
....
Route.use('/nhfinder', nhfinderRoutes)
...
- Create folder uploads like config in step 1. chmod 777.
example:
mkdir ./public/uploads
chmod 0777 ./public/uploads
- Import css in frontend's global file:
...
import '@ngochipx/nhfinder/reactjs/dist/main.css'
- In front-end. In the component need to integrate NHFinder:
....
import NHFinder from '@ngochipx/nhfinder/reactjs'
...
initEditor = async () => {
this.CKEditor = require("@ckeditor/ckeditor5-react");
this.InlineEditor = require("@ngochipx/nhfinder/build-inline");
}
...
render(){
return ... <this.CKEditor editor={this.InlineEditor}
data="<b>Click here to insert content ...</b>"
onInit={editor => { this.editor = editor}}
config={{
imageManagement: {
component: this.refNHFinder,
options: {
apiUrl: "http://localhost:3333/api/v1/nhfinder",
apiKey: "123456"
}}
/>
...
<NHFinder ref={ref => this.refNHFinder = ref} />
}
- Independent use (No need for CK Editor)
...
import NHFinder from '@ngochipx/nhfinder/reactjs'
...
showNHFinder(){
this.refNHFinder.show()
}
render(){
return
...
<NHFinder
ref={ref => this.refNHFinder = ref}
options ={{
apiKey: "123456",
directorySelected: "/",
apiUrl: "http://localhost:3333/api/v1/nhfinder"
onChooseImages: (images) => { console.log(images); }
}}
/>
}
ngochip