Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
prepare 0.6.6 (#79)
Browse files Browse the repository at this point in the history
* issue #78 Add suggestion search bar

* issue #77 Encode download API url

disabling `/file/` API

* update dependencies
  • Loading branch information
Lunik authored Nov 5, 2017
1 parent 44232b0 commit f677bbe
Show file tree
Hide file tree
Showing 9 changed files with 3,239 additions and 2,994 deletions.
6,114 changes: 3,129 additions & 2,985 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@
"express": "^4.16.2",
"fs-extra": "^4.0.2",
"jquery": "^3.2.1",
"material-components-web": "^0.23.0",
"material-components-web": "^0.24.0",
"morgan": "^1.9.0",
"nedb": "^1.8.0",
"react": "~15.6.2",
"react-dom": "~15.6.2",
"react-material-components-web": "^0.1.18",
"socket.io": "^2.0.4",
"socket.io-client": "^2.0.4",
"torrent-search-api": "^1.0.19",
"torrent-search-api": "^1.0.21",
"webtorrent": "^0.98.20"
}
}
7 changes: 6 additions & 1 deletion src/public/components/bar/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Form from '../form/default'
import DialogWindow from '../dialog/default'
import SearchList from '../list/search'
import SearchListItem from '../list/item/search'
import SuggestionInput from '../datalist/suggestion'

export default class SearchBar extends React.Component {
constructor (props) {
Expand Down Expand Up @@ -83,6 +84,8 @@ export default class SearchBar extends React.Component {
}

search (query) {
this.refs.datalist.addItem(query)

this.setState({
loading: true
})
Expand Down Expand Up @@ -176,7 +179,9 @@ export default class SearchBar extends React.Component {
ref="input"
value={this.state.input}
onChange={ (e) => this.setState({input: e.target.value}) }
placeholder="Search, Torrent or Magnet"/>
placeholder="Search, Torrent or Magnet"
list="search-suggestions"/>
<SuggestionInput ref="datalist" id="search-suggestions" />
<Button style={style.button} text={this.state.status} disabled={this.state.input.length <= 0} />
<DialogWindow
open={this.state.dialogOpen}
Expand Down
34 changes: 34 additions & 0 deletions src/public/components/datalist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'

export default class Datalist extends React.Component {
constructor (props) {
super(props)

this.state = {
items: []
}

this.initState(props)
}

initState (props) {
Object.assign(this.state, {
items: props.items
})
}

componentWillReceiveProps (props) {
this.initState(props)
}

render () {
let items = this.state.items.map((item) => (
<option key={item} value={item}/>
))
return (
<datalist id={this.props.id}>
{items}
</datalist>
)
}
}
63 changes: 63 additions & 0 deletions src/public/components/datalist/suggestion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react'

import Datalist from './index'

export default class SuggestionInput extends React.Component {
constructor (props) {
super(props)

this.storageID = '__SearchSuggestions'
this.state = {
items: []
}

this.initState(props)
}

initState (props) {
Object.assign(this.state, {})
this.load()
}

componentWillReceiveProps (props) {
this.initState(props)
}

addItem (item) {
if (this.state.items.indexOf(item) === -1) {
let temp = this.state.items
temp.push(item)

this.setState({
items: temp
})

this.save()
}
}

save () {
window.localStorage.setItem(this.storageID, JSON.stringify(this.state.items))
}

load () {
try {
let stored = JSON.parse(window.localStorage.getItem(this.storageID))

if (!stored) {
throw new Error('LocalStorage empty')
}

this.state.items = JSON.parse(window.localStorage.getItem(this.storageID))
} catch (e) {
this.state.items = []
this.save()
}
}

render () {
return (
<Datalist id={this.props.id} items={this.state.items}/>
)
}
}
1 change: 1 addition & 0 deletions src/public/components/input/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class TextInput extends React.Component {
style={Object.assign(style.input, this.props.style.input)}
type={this.props.type} id={this.props.id}
onChange={ (e) => this.props.onChange(e) }
list={this.props.list}
/>
<Textfield.Label htmlFor={this.props.id}>
{this.props.placeholder}
Expand Down
2 changes: 1 addition & 1 deletion src/public/components/toolbox/item/file/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class CopyToolboxItem extends React.Component {
}

handleClick () {
copy(window.location.origin + this.props.file.copy)
copy(window.location.origin + this.props.file.download)
}

render () {
Expand Down
4 changes: 1 addition & 3 deletions src/server/model/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ export default class File extends EventEmitter {
toJSON () {
let cleanBase = this.base.split('/').slice(2).join('/')
let url = Path.join('/folder', cleanBase, this.name)
let download = Path.join('/file', cleanBase, this.name)
let copy = '/dl/' + Crypto.Rabbit.encrypt(Path.join(cleanBase, this.name), config.server.masterKey).toString()
let download = '/dl/' + Crypto.Rabbit.encrypt(Path.join(cleanBase, this.name), config.server.masterKey).toString()
let path = Path.join(cleanBase, this.name)
return {
name: this.name,
Expand All @@ -133,7 +132,6 @@ export default class File extends EventEmitter {
childs: this.childs,
url,
download: this instanceof Folder ? null : download,
copy: this instanceof Folder ? null : copy,
path: this instanceof Folder ? path : null
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/routes/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const config = new Config({sync: true})
var log = new Delogger('File')

module.exports = (app, baseFolder) => {
app.get('/file/:path((*)/?*)', (req, res) => {
/* app.get('/file/:path((*)/?*)', (req, res) => {
var path = req.params.path
Download(req, res, path)
})
}) */

app.get('/dl/:file(*)', (req, res) => {
var path = Crypto.Rabbit.decrypt(req.params.file, config.server.masterKey).toString(Crypto.enc.Utf8)
Expand Down

0 comments on commit f677bbe

Please sign in to comment.