mirror of
https://github.com/simon987/sist2.git
synced 2025-12-13 15:29:04 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 373ac01e4e | |||
| 893ff145c5 | |||
| 6111ded77f | |||
| 34cc26b2fd | |||
| 204034d859 | |||
| 16ccc6c0d3 | |||
| 94c617fdc3 | |||
| ebfd7e03ce | |||
| 6931d320a2 | |||
| fc22e52eae | |||
| ba81748a74 | |||
| e72fa1587b | |||
| ea4fb7fa0d | |||
| b0a868bb73 | |||
| d761a3b595 | |||
| 2d7a8a2fdc | |||
| 152d2ddf8a | |||
| bc5f22b759 | |||
| 534b397876 |
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -25,3 +25,9 @@
|
|||||||
[submodule "lib/harfbuzz"]
|
[submodule "lib/harfbuzz"]
|
||||||
path = lib/harfbuzz
|
path = lib/harfbuzz
|
||||||
url = https://github.com/harfbuzz/harfbuzz
|
url = https://github.com/harfbuzz/harfbuzz
|
||||||
|
[submodule "lib/libmagic"]
|
||||||
|
path = lib/libmagic
|
||||||
|
url = https://github.com/threatstack/libmagic
|
||||||
|
[submodule "lib/bzip2-1.0.6"]
|
||||||
|
path = lib/bzip2-1.0.6
|
||||||
|
url = https://github.com/enthought/bzip2-1.0.6
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ if (WITH_SIST2)
|
|||||||
src/parsing/text.h src/parsing/text.c
|
src/parsing/text.h src/parsing/text.c
|
||||||
src/index/web.c src/index/web.h
|
src/index/web.c src/index/web.h
|
||||||
src/web/serve.c src/web/serve.h
|
src/web/serve.c src/web/serve.h
|
||||||
|
src/web/auth_basic.h src/web/auth_basic.c
|
||||||
src/index/elastic.c src/index/elastic.h
|
src/index/elastic.c src/index/elastic.h
|
||||||
src/util.c src/util.h
|
src/util.c src/util.h
|
||||||
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
src/ctx.h src/types.h src/parsing/font.c src/parsing/font.h
|
||||||
|
|||||||
9
Docker/Dockerfile
Normal file
9
Docker/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
FROM ubuntu:19.10
|
||||||
|
MAINTAINER simon987 <me@simon987.net>
|
||||||
|
|
||||||
|
RUN apt update
|
||||||
|
RUN apt install -y libglib2.0-0 libcurl4 libmagic1 libharfbuzz-bin libopenjp2-7
|
||||||
|
|
||||||
|
ADD sist2 /root/sist2
|
||||||
|
|
||||||
|
ENTRYPOINT ["/root/sist2"]
|
||||||
9
Docker/build.sh
Executable file
9
Docker/build.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
rm ./sist2
|
||||||
|
cp ../sist2 .
|
||||||
|
|
||||||
|
version=$(./sist2 --version)
|
||||||
|
|
||||||
|
echo "Version ${version}"
|
||||||
|
docker build . -t simon987/sist2:${version} -t simon987/sist2:latest
|
||||||
|
docker push simon987/sist2:${version}
|
||||||
|
docker push simon987/sist2:latest
|
||||||
50
README.md
50
README.md
@@ -9,11 +9,12 @@ sist2 (Simple incremental search tool)
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* Fast, low memory usage
|
* Fast, low memory usage, multi-threaded
|
||||||
* Portable (all its features are packaged in a single executable)
|
* Portable (all its features are packaged in a single executable)
|
||||||
* Extracts text from common file types\*
|
* Extracts text from common file types\*
|
||||||
* Generates thumbnails\*
|
* Generates thumbnails\*
|
||||||
* Incremental scanning
|
* Incremental scanning
|
||||||
|
* Automatic tagging from file attributes via [user scripts](scripting/README.md)
|
||||||
|
|
||||||
|
|
||||||
\* See [format support](#format-support)
|
\* See [format support](#format-support)
|
||||||
@@ -21,11 +22,13 @@ sist2 (Simple incremental search tool)
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
1. Have an [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) instance running
|
1. Have an [Elasticsearch](https://www.elastic.co/downloads/elasticsearch) instance running
|
||||||
1. Download the [latest sist2 release](https://github.com/simon987/sist2/releases)
|
1.
|
||||||
|
1. Download the [latest sist2 release](https://github.com/simon987/sist2/releases) *
|
||||||
|
1. *(or)* `docker pull simon987/sist2:latest`
|
||||||
|
|
||||||
*Windows users*: `sist2` runs under [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
|
|
||||||
|
|
||||||
*Mac users*: See [#1](https://github.com/simon987/sist2/issues/1)
|
\* *Windows users*: **sist2** runs under [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux)
|
||||||
|
\* *Mac users*: See [#1](https://github.com/simon987/sist2/issues/1)
|
||||||
|
|
||||||
|
|
||||||
## Example usage
|
## Example usage
|
||||||
@@ -52,14 +55,40 @@ sist2 index --print ./my_idx > raw_documents.ndjson
|
|||||||
sist2 web --bind 0.0.0.0 --port 4321 ./my_idx1 ./my_idx2 ./my_idx3
|
sist2 web --bind 0.0.0.0 --port 4321 ./my_idx1 ./my_idx2 ./my_idx3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Use sist2 with docker
|
||||||
|
|
||||||
|
**scan**
|
||||||
|
```bash
|
||||||
|
docker run -it \
|
||||||
|
-v /path/to/files/:/files \
|
||||||
|
-v $PWD/out/:/out \
|
||||||
|
simon987/sist2 scan -t 4 /files -o /out/my_idx1
|
||||||
|
```
|
||||||
|
**index**
|
||||||
|
```bash
|
||||||
|
docker run -it --network host\
|
||||||
|
-v $PWD/out/:/out \
|
||||||
|
simon987/sist2 index /out/my_idx1
|
||||||
|
```
|
||||||
|
|
||||||
|
**web**
|
||||||
|
```bash
|
||||||
|
docker run --rm --network host -d --name sist2\
|
||||||
|
-v $PWD/out/my_idx:/idx \
|
||||||
|
-v $PWD/my/files:/files
|
||||||
|
simon987/sist2 web --bind 0.0.0.0 /idx
|
||||||
|
docker stop sist2
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Format support
|
## Format support
|
||||||
|
|
||||||
File type | Library | Content | Thumbnail | Metadata
|
File type | Library | Content | Thumbnail | Metadata
|
||||||
:---|:---|:---|:---|:---
|
:---|:---|:---|:---|:---
|
||||||
pdf,xps,cbz,cbr,fb2,epub | MuPDF | yes | yes, `png` | title |
|
pdf,xps,cbz,fb2,epub | MuPDF | yes | yes, `png` | title |
|
||||||
`audio/*` | libav | - | yes, `jpeg` | ID3 tags |
|
`audio/*` | ffmpeg | - | yes, `jpeg` | ID3 tags |
|
||||||
`video/*` | libav | - | yes, `jpeg` | title, comment |
|
`video/*` | ffmpeg | - | yes, `jpeg` | title, comment, artist |
|
||||||
`image/*` | libav | - | yes, `jpeg` | *planned* |
|
`image/*` | ffmpeg | - | yes, `jpeg` | `EXIF:Artist`, `EXIF:ImageDescription` |
|
||||||
ttf,ttc,cff,woff,fnt,otf | Freetype2 | - | yes, `bmp` | Name & style |
|
ttf,ttc,cff,woff,fnt,otf | Freetype2 | - | yes, `bmp` | Name & style |
|
||||||
`text/plain` | *(none)* | yes | no | - |
|
`text/plain` | *(none)* | yes | no | - |
|
||||||
docx, xlsx, pptx | | *planned* | no | *planned* |
|
docx, xlsx, pptx | | *planned* | no | *planned* |
|
||||||
@@ -79,11 +108,12 @@ binaries.
|
|||||||
apt install git cmake pkg-config libglib2.0-dev\
|
apt install git cmake pkg-config libglib2.0-dev\
|
||||||
libssl-dev uuid-dev libavformat-dev libswscale-dev \
|
libssl-dev uuid-dev libavformat-dev libswscale-dev \
|
||||||
python3 libmagic-dev libfreetype6-dev libcurl-dev \
|
python3 libmagic-dev libfreetype6-dev libcurl-dev \
|
||||||
libbz2-dev yasm
|
libbz2-dev yasm libharfbuzz-dev ragel
|
||||||
```
|
```
|
||||||
*(FreeBSD)*
|
*(FreeBSD)*
|
||||||
```bash
|
```bash
|
||||||
pkg install cmake gcc yasm gmake bash ffmpeg e2fsprogs-uuid
|
pkg install cmake gcc yasm gmake bash ffmpeg e2fsprogs-uuid\
|
||||||
|
autotools ragel
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Build
|
2. Build
|
||||||
|
|||||||
1
lib/bzip2-1.0.6
Submodule
1
lib/bzip2-1.0.6
Submodule
Submodule lib/bzip2-1.0.6 added at 288acf97a1
Submodule lib/ffmpeg updated: 0481a1f6e5...53c21c2d6b
Submodule lib/harfbuzz updated: 7cde68f10c...878e3588a3
1
lib/libmagic
Submodule
1
lib/libmagic
Submodule
Submodule lib/libmagic added at 1249b5cd02
Submodule lib/mupdf updated: 91782a4348...355cedaefe
@@ -80,6 +80,9 @@
|
|||||||
"analyzer": "my_nGram"
|
"analyzer": "my_nGram"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tag": {
|
||||||
|
"type": "keyword"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
117
scripting/README.md
Normal file
117
scripting/README.md
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
## User scripts
|
||||||
|
|
||||||
|
*This document is under construction, more in-depth guide coming soon*
|
||||||
|
|
||||||
|
During the `index` step, you can use the `--script-file <script>` option to
|
||||||
|
modify documents or add user tags. This option is mainly used to
|
||||||
|
implement automatic tagging based on file attributes.
|
||||||
|
|
||||||
|
The scripting language used
|
||||||
|
([Painless Scripting Language](https://www.elastic.co/guide/en/elasticsearch/painless/7.4/index.html))
|
||||||
|
is very similar to Java, but you should be able to create user scripts
|
||||||
|
without programming experience at all if you're somewhat familiar with
|
||||||
|
regex.
|
||||||
|
|
||||||
|
This is the base structure of the documents we're working with:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"_id": "e171405c-fdb5-4feb-bb32-82637bc32084",
|
||||||
|
"_index": "sist2",
|
||||||
|
"_type": "_doc",
|
||||||
|
"_source": {
|
||||||
|
"index": "206b3050-e821-421a-891d-12fcf6c2db0d",
|
||||||
|
"mime": "application/json",
|
||||||
|
"size": 1799,
|
||||||
|
"mtime": 1545443685,
|
||||||
|
"extension": "md",
|
||||||
|
"name": "README",
|
||||||
|
"path": "sist2/scripting",
|
||||||
|
"content": "..."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example script**
|
||||||
|
|
||||||
|
This script checks if the `genre` attribute exists, if it does
|
||||||
|
it adds the `genre.<genre>` tag.
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
if (ctx._source?.genre != null) {
|
||||||
|
tags.add("genre." + ctx._source.genre.toLowerCase())
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use `.` to create a hierarchical tag tree:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
To use regular expressions, you need to add this line in `/etc/elasticsearch/elasticsearch.yml`
|
||||||
|
```yaml
|
||||||
|
script.painless.regex.enabled: true
|
||||||
|
```
|
||||||
|
Or, if you're using docker add `-e "script.painless.regex.enabled=true"`
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
If `(20XX)` is in the file name, add the `year.<year>` tag:
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
Matcher m = /[\(\.+](20[0-9]{2})[\)\.+]/.matcher(ctx._source.name);
|
||||||
|
if (m.find()) {
|
||||||
|
tags.add("year." + m.group(1))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use default *Calibre* folder structure to infer author.
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
// We expect the book path to look like this:
|
||||||
|
// /path/to/Calibre Library/Author/Title/Title - Author.pdf
|
||||||
|
|
||||||
|
if (ctx._source.name.contains("-") && ctx._source.extension == "pdf") {
|
||||||
|
String[] names = ctx._source.name.splitOnToken('-');
|
||||||
|
tags.add("author." + names[1].strip());
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If the file matches a specific pattern `AAAA-000 fName1 lName1, <fName2 lName2>...`, add the `actress.<actress>` and
|
||||||
|
`studio.<studio>` tag:
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
Matcher m = /([A-Z]{4})-[0-9]{3} (.*)/.matcher(ctx._source.name);
|
||||||
|
if (m.find()) {
|
||||||
|
tags.add("studio." + m.group(1));
|
||||||
|
|
||||||
|
// Take the matched group (.*), and add a tag for
|
||||||
|
// each name, separated by comma
|
||||||
|
for (String name : m.group(2).splitOnToken(',')) {
|
||||||
|
tags.add("actress." + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Set the name of the last folder (`/path/to/<studio>/file.mp4`) to `studio.<studio>` tag
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
if (ctx._source.path != "") {
|
||||||
|
String[] names = ctx._source.path.splitOnToken('/');
|
||||||
|
tags.add("studio." + names[names.length-1]);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Set the name of the last folder (`/path/to/<studio>/file.mp4`) to `studio.<studio>` tag
|
||||||
|
```Java
|
||||||
|
ArrayList tags = ctx._source.tag = new ArrayList();
|
||||||
|
|
||||||
|
if (ctx._source.path != "") {
|
||||||
|
String[] names = ctx._source.path.splitOnToken('/');
|
||||||
|
tags.add("studio." + names[names.length-1]);
|
||||||
|
}
|
||||||
|
```
|
||||||
BIN
scripting/genre_example.png
Normal file
BIN
scripting/genre_example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@@ -54,14 +54,12 @@ cd ../..
|
|||||||
mv onion/build/src/onion/libonion_static.a .
|
mv onion/build/src/onion/libonion_static.a .
|
||||||
|
|
||||||
#bzip2
|
#bzip2
|
||||||
git clone https://github.com/enthought/bzip2-1.0.6
|
|
||||||
cd bzip2-1.0.6
|
cd bzip2-1.0.6
|
||||||
make -j 4
|
make -j 4
|
||||||
cd ..
|
cd ..
|
||||||
mv bzip2-1.0.6/libbz2.a .
|
mv bzip2-1.0.6/libbz2.a .
|
||||||
|
|
||||||
# magic
|
# magic
|
||||||
git clone https://github.com/threatstack/libmagic
|
|
||||||
cd libmagic
|
cd libmagic
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --enable-static --disable-shared
|
./configure --enable-static --disable-shared
|
||||||
|
|||||||
@@ -42,14 +42,12 @@ mv ffmpeg/libswresample/libswresample.a .
|
|||||||
mv ffmpeg/libswscale/libswscale.a .
|
mv ffmpeg/libswscale/libswscale.a .
|
||||||
|
|
||||||
#bzip2
|
#bzip2
|
||||||
git clone https://github.com/enthought/bzip2-1.0.6
|
|
||||||
cd bzip2-1.0.6
|
cd bzip2-1.0.6
|
||||||
make -j 4
|
make -j 4
|
||||||
cd ..
|
cd ..
|
||||||
mv bzip2-1.0.6/libbz2.a .
|
mv bzip2-1.0.6/libbz2.a .
|
||||||
|
|
||||||
# magic
|
# magic
|
||||||
git clone https://github.com/threatstack/libmagic
|
|
||||||
cd libmagic
|
cd libmagic
|
||||||
./autogen.sh
|
./autogen.sh
|
||||||
./configure --enable-static --disable-shared
|
./configure --enable-static --disable-shared
|
||||||
|
|||||||
53
src/cli.c
53
src/cli.c
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
#define DEFAULT_OUTPUT "index.sist2/"
|
#define DEFAULT_OUTPUT "index.sist2/"
|
||||||
#define DEFAULT_CONTENT_SIZE 4096
|
#define DEFAULT_CONTENT_SIZE 4096
|
||||||
#define DEFAULT_QUALITY 15
|
#define DEFAULT_QUALITY 5
|
||||||
#define DEFAULT_SIZE 200
|
#define DEFAULT_SIZE 500
|
||||||
#define DEFAULT_REWRITE_URL ""
|
#define DEFAULT_REWRITE_URL ""
|
||||||
|
|
||||||
#define DEFAULT_ES_URL "http://localhost:9200"
|
#define DEFAULT_ES_URL "http://localhost:9200"
|
||||||
@@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
scan_args_t *scan_args_create() {
|
scan_args_t *scan_args_create() {
|
||||||
scan_args_t *args = calloc(sizeof(scan_args_t), 1);
|
scan_args_t *args = calloc(sizeof(scan_args_t), 1);
|
||||||
|
|
||||||
|
args->depth = -1;
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +28,7 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
|
|
||||||
char *abs_path = abspath(argv[1]);
|
char *abs_path = abspath(argv[1]);
|
||||||
if (abs_path == NULL) {
|
if (abs_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s", argv[1]);
|
fprintf(stderr, "File not found: %s\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
args->path = abs_path;
|
args->path = abs_path;
|
||||||
@@ -34,7 +37,7 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
if (args->incremental != NULL) {
|
if (args->incremental != NULL) {
|
||||||
abs_path = abspath(args->incremental);
|
abs_path = abspath(args->incremental);
|
||||||
if (abs_path == NULL) {
|
if (abs_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s", args->incremental);
|
fprintf(stderr, "File not found: %s\n", args->incremental);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,6 +83,12 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->depth < 0) {
|
||||||
|
args->depth = G_MAXINT32;
|
||||||
|
} else {
|
||||||
|
args->depth += 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (args->name == NULL) {
|
if (args->name == NULL) {
|
||||||
args->name = g_path_get_basename(args->output);
|
args->name = g_path_get_basename(args->output);
|
||||||
}
|
}
|
||||||
@@ -100,7 +109,7 @@ int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
|||||||
|
|
||||||
char *index_path = abspath(argv[1]);
|
char *index_path = abspath(argv[1]);
|
||||||
if (index_path == NULL) {
|
if (index_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s", argv[1]);
|
fprintf(stderr, "File not found: %s\n", argv[1]);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
args->index_path = argv[1];
|
args->index_path = argv[1];
|
||||||
@@ -109,6 +118,32 @@ int index_args_validate(index_args_t *args, int argc, const char **argv) {
|
|||||||
if (args->es_url == NULL) {
|
if (args->es_url == NULL) {
|
||||||
args->es_url = DEFAULT_ES_URL;
|
args->es_url = DEFAULT_ES_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->script_path != NULL) {
|
||||||
|
struct stat info;
|
||||||
|
int res = stat(args->script_path, &info);
|
||||||
|
|
||||||
|
if (res == -1) {
|
||||||
|
fprintf(stderr, "Error opening script file '%s': %s\n", args->script_path, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fd = open(args->script_path, O_RDONLY);
|
||||||
|
if (fd == -1) {
|
||||||
|
fprintf(stderr, "Error opening script file '%s': %s\n", args->script_path, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
args->script = malloc(info.st_size + 1);
|
||||||
|
res = read(fd, args->script, info.st_size);
|
||||||
|
if (res == -1) {
|
||||||
|
fprintf(stderr, "Error reading script file '%s': %s\n", args->script_path, strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*(args->script + info.st_size) = '\0';
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,13 +166,19 @@ int web_args_validate(web_args_t *args, int argc, const char **argv) {
|
|||||||
args->port = DEFAULT_PORT;
|
args->port = DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args->credentials != NULL) {
|
||||||
|
args->b64credentials = onion_base64_encode(args->credentials, (int)strlen(args->credentials));
|
||||||
|
//Remove trailing newline
|
||||||
|
*(args->b64credentials + strlen(args->b64credentials) - 1) = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
args->index_count = argc - 1;
|
args->index_count = argc - 1;
|
||||||
args->indices = argv + 1;
|
args->indices = argv + 1;
|
||||||
|
|
||||||
for (int i = 0; i < args->index_count; i++) {
|
for (int i = 0; i < args->index_count; i++) {
|
||||||
char *abs_path = abspath(args->indices[i]);
|
char *abs_path = abspath(args->indices[i]);
|
||||||
if (abs_path == NULL) {
|
if (abs_path == NULL) {
|
||||||
fprintf(stderr, "File not found: %s", abs_path);
|
fprintf(stderr, "File not found: %s\n", abs_path);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ typedef struct scan_args {
|
|||||||
char *output;
|
char *output;
|
||||||
char *rewrite_url;
|
char *rewrite_url;
|
||||||
char *name;
|
char *name;
|
||||||
|
int depth;
|
||||||
char *path;
|
char *path;
|
||||||
} scan_args_t;
|
} scan_args_t;
|
||||||
|
|
||||||
@@ -22,6 +23,8 @@ int scan_args_validate(scan_args_t *args, int argc, const char **argv);
|
|||||||
typedef struct index_args {
|
typedef struct index_args {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
const char *index_path;
|
const char *index_path;
|
||||||
|
const char *script_path;
|
||||||
|
char *script;
|
||||||
int print;
|
int print;
|
||||||
int force_reset;
|
int force_reset;
|
||||||
} index_args_t;
|
} index_args_t;
|
||||||
@@ -30,6 +33,8 @@ typedef struct web_args {
|
|||||||
char *es_url;
|
char *es_url;
|
||||||
char *bind;
|
char *bind;
|
||||||
char *port;
|
char *port;
|
||||||
|
char *credentials;
|
||||||
|
char *b64credentials;
|
||||||
int index_count;
|
int index_count;
|
||||||
const char **indices;
|
const char **indices;
|
||||||
} web_args_t;
|
} web_args_t;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ struct {
|
|||||||
int threads;
|
int threads;
|
||||||
int content_size;
|
int content_size;
|
||||||
float tn_qscale;
|
float tn_qscale;
|
||||||
|
int depth;
|
||||||
|
|
||||||
size_t stat_tn_size;
|
size_t stat_tn_size;
|
||||||
size_t stat_index_size;
|
size_t stat_index_size;
|
||||||
@@ -34,6 +35,7 @@ struct {
|
|||||||
struct {
|
struct {
|
||||||
char *es_url;
|
char *es_url;
|
||||||
int index_count;
|
int index_count;
|
||||||
|
char* b64credentials;
|
||||||
struct index_t indices[16];
|
struct index_t indices[16];
|
||||||
} WebCtx;
|
} WebCtx;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <cJSON/cJSON.h>
|
#include <cJSON/cJSON.h>
|
||||||
#include <src/ctx.h>
|
|
||||||
|
|
||||||
#include "static_generated.c"
|
#include "static_generated.c"
|
||||||
|
|
||||||
@@ -54,6 +53,40 @@ void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]) {
|
|||||||
elastic_index_line(bulk_line);
|
elastic_index_line(bulk_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void execute_update_script(const char *script, const char index_id[UUID_STR_LEN]) {
|
||||||
|
|
||||||
|
cJSON *body = cJSON_CreateObject();
|
||||||
|
cJSON *script_obj = cJSON_AddObjectToObject(body, "script");
|
||||||
|
cJSON_AddStringToObject(script_obj, "lang", "painless");
|
||||||
|
cJSON_AddStringToObject(script_obj, "source", script);
|
||||||
|
|
||||||
|
cJSON *query = cJSON_AddObjectToObject(body, "query");
|
||||||
|
cJSON *term_obj = cJSON_AddObjectToObject(query, "term");
|
||||||
|
cJSON_AddStringToObject(term_obj, "index", index_id);
|
||||||
|
|
||||||
|
char * str = cJSON_Print(body);
|
||||||
|
|
||||||
|
char bulk_url[4096];
|
||||||
|
snprintf(bulk_url, 4096, "%s/sist2/_update_by_query?pretty", Indexer->es_url);
|
||||||
|
response_t *r = web_post(bulk_url, str, "Content-Type: application/json");
|
||||||
|
printf("Executed user script <%d>\n", r->status_code);
|
||||||
|
cJSON *resp = cJSON_Parse(r->body);
|
||||||
|
|
||||||
|
cJSON_free(str);
|
||||||
|
cJSON_Delete(body);
|
||||||
|
free_response(r);
|
||||||
|
|
||||||
|
cJSON *error = cJSON_GetObjectItem(resp, "error");
|
||||||
|
if (error != NULL) {
|
||||||
|
char *error_str = cJSON_Print(error);
|
||||||
|
|
||||||
|
fprintf(stderr, "User script error: \n%s\n", error_str);
|
||||||
|
cJSON_free(error_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(resp);
|
||||||
|
}
|
||||||
|
|
||||||
void elastic_flush() {
|
void elastic_flush() {
|
||||||
|
|
||||||
if (Indexer == NULL) {
|
if (Indexer == NULL) {
|
||||||
@@ -98,6 +131,12 @@ void elastic_flush() {
|
|||||||
char bulk_url[4096];
|
char bulk_url[4096];
|
||||||
snprintf(bulk_url, 4096, "%s/sist2/_bulk", Indexer->es_url);
|
snprintf(bulk_url, 4096, "%s/sist2/_bulk", Indexer->es_url);
|
||||||
response_t *r = web_post(bulk_url, buf, "Content-Type: application/x-ndjson");
|
response_t *r = web_post(bulk_url, buf, "Content-Type: application/x-ndjson");
|
||||||
|
|
||||||
|
if (r->status_code == 0) {
|
||||||
|
fprintf(stderr, "Could not connect to %s, make sure that elasticsearch is running!\n", IndexCtx.es_url);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
printf("Indexed %3d documents (%zukB) <%d>\n", count, buf_cur / 1024, r->status_code);
|
printf("Indexed %3d documents (%zukB) <%d>\n", count, buf_cur / 1024, r->status_code);
|
||||||
|
|
||||||
cJSON *ret_json = cJSON_Parse(r->body);
|
cJSON *ret_json = cJSON_Parse(r->body);
|
||||||
@@ -115,6 +154,7 @@ void elastic_flush() {
|
|||||||
cJSON_Delete(ret_json);
|
cJSON_Delete(ret_json);
|
||||||
|
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void elastic_index_line(es_bulk_line_t *line) {
|
void elastic_index_line(es_bulk_line_t *line) {
|
||||||
@@ -140,8 +180,7 @@ void elastic_index_line(es_bulk_line_t *line) {
|
|||||||
|
|
||||||
es_indexer_t *create_indexer(const char *url) {
|
es_indexer_t *create_indexer(const char *url) {
|
||||||
|
|
||||||
size_t url_len = strlen(url);
|
char *es_url = malloc(strlen(url) + 1);
|
||||||
char *es_url = malloc(url_len);
|
|
||||||
strcpy(es_url, url);
|
strcpy(es_url, url);
|
||||||
|
|
||||||
es_indexer_t *indexer = malloc(sizeof(es_indexer_t));
|
es_indexer_t *indexer = malloc(sizeof(es_indexer_t));
|
||||||
@@ -154,7 +193,7 @@ es_indexer_t *create_indexer(const char *url) {
|
|||||||
return indexer;
|
return indexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_indexer() {
|
void destroy_indexer(char * script, char index_id[UUID_STR_LEN]) {
|
||||||
|
|
||||||
char url[4096];
|
char url[4096];
|
||||||
|
|
||||||
@@ -163,6 +202,15 @@ void destroy_indexer() {
|
|||||||
printf("Refresh index <%d>\n", r->status_code);
|
printf("Refresh index <%d>\n", r->status_code);
|
||||||
free_response(r);
|
free_response(r);
|
||||||
|
|
||||||
|
if (script != NULL) {
|
||||||
|
execute_update_script(script, index_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(url, sizeof(url), "%s/sist2/_refresh", IndexCtx.es_url);
|
||||||
|
r = web_post(url, "", NULL);
|
||||||
|
printf("Refresh index <%d>\n", r->status_code);
|
||||||
|
free_response(r);
|
||||||
|
|
||||||
snprintf(url, sizeof(url), "%s/sist2/_forcemerge", IndexCtx.es_url);
|
snprintf(url, sizeof(url), "%s/sist2/_forcemerge", IndexCtx.es_url);
|
||||||
r = web_post(url, "", NULL);
|
r = web_post(url, "", NULL);
|
||||||
printf("Merge index <%d>\n", r->status_code);
|
printf("Merge index <%d>\n", r->status_code);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ void index_json(cJSON *document, const char uuid_str[UUID_STR_LEN]);
|
|||||||
|
|
||||||
es_indexer_t *create_indexer(const char* es_url);
|
es_indexer_t *create_indexer(const char* es_url);
|
||||||
|
|
||||||
void destroy_indexer();
|
void destroy_indexer(char *script, char index_id[UUID_STR_LEN]);
|
||||||
|
|
||||||
void elastic_init(int force_reset);
|
void elastic_init(int force_reset);
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -54,6 +54,12 @@ index_descriptor_t read_index_descriptor(char *path) {
|
|||||||
struct stat info;
|
struct stat info;
|
||||||
stat(path, &info);
|
stat(path, &info);
|
||||||
int fd = open(path, O_RDONLY);
|
int fd = open(path, O_RDONLY);
|
||||||
|
|
||||||
|
if (fd == -1) {
|
||||||
|
fprintf(stderr, "Invalid/corrupt index (Could not find descriptor)\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
char *buf = malloc(info.st_size + 1);
|
char *buf = malloc(info.st_size + 1);
|
||||||
read(fd, buf, info.st_size);
|
read(fd, buf, info.st_size);
|
||||||
*(buf + info.st_size) = '\0';
|
*(buf + info.st_size) = '\0';
|
||||||
@@ -66,7 +72,7 @@ index_descriptor_t read_index_descriptor(char *path) {
|
|||||||
strcpy(descriptor.root, cJSON_GetObjectItem(json, "root")->valuestring);
|
strcpy(descriptor.root, cJSON_GetObjectItem(json, "root")->valuestring);
|
||||||
strcpy(descriptor.name, cJSON_GetObjectItem(json, "name")->valuestring);
|
strcpy(descriptor.name, cJSON_GetObjectItem(json, "name")->valuestring);
|
||||||
strcpy(descriptor.rewrite_url, cJSON_GetObjectItem(json, "rewrite_url")->valuestring);
|
strcpy(descriptor.rewrite_url, cJSON_GetObjectItem(json, "rewrite_url")->valuestring);
|
||||||
descriptor.root_len = (short)strlen(descriptor.root);
|
descriptor.root_len = (short) strlen(descriptor.root);
|
||||||
strcpy(descriptor.version, cJSON_GetObjectItem(json, "version")->valuestring);
|
strcpy(descriptor.version, cJSON_GetObjectItem(json, "version")->valuestring);
|
||||||
strcpy(descriptor.uuid, cJSON_GetObjectItem(json, "uuid")->valuestring);
|
strcpy(descriptor.uuid, cJSON_GetObjectItem(json, "uuid")->valuestring);
|
||||||
|
|
||||||
@@ -181,7 +187,7 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
uuid_unparse(line.uuid, uuid_str);
|
uuid_unparse(line.uuid, uuid_str);
|
||||||
|
|
||||||
cJSON_AddStringToObject(document, "mime", mime_get_mime_text(line.mime));
|
cJSON_AddStringToObject(document, "mime", mime_get_mime_text(line.mime));
|
||||||
cJSON_AddNumberToObject(document, "size", (double)line.size);
|
cJSON_AddNumberToObject(document, "size", (double) line.size);
|
||||||
cJSON_AddNumberToObject(document, "mtime", line.mtime);
|
cJSON_AddNumberToObject(document, "mtime", line.mtime);
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
@@ -208,14 +214,19 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
while (key != '\n') {
|
while (key != '\n') {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case MetaWidth:
|
case MetaWidth:
|
||||||
case MetaHeight:
|
case MetaHeight: {
|
||||||
case MetaMediaDuration:
|
|
||||||
case MetaMediaBitrate: {
|
|
||||||
int value;
|
int value;
|
||||||
fread(&value, sizeof(int), 1, file);
|
fread(&value, sizeof(int), 1, file);
|
||||||
cJSON_AddNumberToObject(document, get_meta_key_text(key), value);
|
cJSON_AddNumberToObject(document, get_meta_key_text(key), value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case MetaMediaDuration:
|
||||||
|
case MetaMediaBitrate: {
|
||||||
|
long value;
|
||||||
|
fread(&value, sizeof(long), 1, file);
|
||||||
|
cJSON_AddNumberToObject(document, get_meta_key_text(key), value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case MetaMediaAudioCodec:
|
case MetaMediaAudioCodec:
|
||||||
case MetaMediaVideoCodec: {
|
case MetaMediaVideoCodec: {
|
||||||
int value;
|
int value;
|
||||||
@@ -245,7 +256,7 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Invalid meta key (corrupt index): %x", key);
|
fprintf(stderr, "Invalid meta key (corrupt index): %x\n", key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,8 +264,9 @@ void read_index(const char *path, const char index_id[UUID_STR_LEN], index_func
|
|||||||
}
|
}
|
||||||
|
|
||||||
func(document, uuid_str);
|
func(document, uuid_str);
|
||||||
cJSON_free(document);
|
cJSON_Delete(document);
|
||||||
}
|
}
|
||||||
|
dyn_buffer_destroy(&buf);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ store_t *store_create(char *path) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (open_ret != 0) {
|
if (open_ret != 0) {
|
||||||
fprintf(stderr, "Error while opening store: %s", mdb_strerror(open_ret));
|
fprintf(stderr, "Error while opening store: %s (%s)\n", mdb_strerror(open_ret), path);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ parse_job_t *create_parse_job(const char *filepath, const struct stat *info, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) {
|
int handle_entry(const char *filepath, const struct stat *info, int typeflag, struct FTW *ftw) {
|
||||||
if (typeflag == FTW_F && S_ISREG(info->st_mode)) {
|
if (ftw->level <= ScanCtx.depth && typeflag == FTW_F && S_ISREG(info->st_mode)) {
|
||||||
parse_job_t *job = create_parse_job(filepath, info, ftw->base);
|
parse_job_t *job = create_parse_job(filepath, info, ftw->base);
|
||||||
tpool_add_work(ScanCtx.pool, parse, job);
|
tpool_add_work(ScanCtx.pool, parse, job);
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/main.c
24
src/main.c
@@ -10,7 +10,7 @@
|
|||||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
||||||
|
|
||||||
|
|
||||||
static const char *const Version = "1.1.0";
|
static const char *const Version = "1.1.8";
|
||||||
static const char *const usage[] = {
|
static const char *const usage[] = {
|
||||||
"sist2 scan [OPTION]... PATH",
|
"sist2 scan [OPTION]... PATH",
|
||||||
"sist2 index [OPTION]... INDEX",
|
"sist2 index [OPTION]... INDEX",
|
||||||
@@ -53,6 +53,7 @@ void sist2_scan(scan_args_t *args) {
|
|||||||
ScanCtx.tn_size = args->size;
|
ScanCtx.tn_size = args->size;
|
||||||
ScanCtx.content_size = args->content_size;
|
ScanCtx.content_size = args->content_size;
|
||||||
ScanCtx.threads = args->threads;
|
ScanCtx.threads = args->threads;
|
||||||
|
ScanCtx.depth = args->depth;
|
||||||
strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path));
|
strncpy(ScanCtx.index.path, args->output, sizeof(ScanCtx.index.path));
|
||||||
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name));
|
strncpy(ScanCtx.index.desc.name, args->name, sizeof(ScanCtx.index.desc.name));
|
||||||
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
|
strncpy(ScanCtx.index.desc.root, args->path, sizeof(ScanCtx.index.desc.root));
|
||||||
@@ -163,10 +164,11 @@ void sist2_index(index_args_t *args) {
|
|||||||
read_index(file_path, desc.uuid, f);
|
read_index(file_path, desc.uuid, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
closedir(dir);
|
||||||
|
|
||||||
if (!args->print) {
|
if (!args->print) {
|
||||||
elastic_flush();
|
elastic_flush();
|
||||||
destroy_indexer();
|
destroy_indexer(args->script, desc.uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +176,7 @@ void sist2_web(web_args_t *args) {
|
|||||||
|
|
||||||
WebCtx.es_url = args->es_url;
|
WebCtx.es_url = args->es_url;
|
||||||
WebCtx.index_count = args->index_count;
|
WebCtx.index_count = args->index_count;
|
||||||
|
WebCtx.b64credentials = args->b64credentials;
|
||||||
|
|
||||||
for (int i = 0; i < args->index_count; i++) {
|
for (int i = 0; i < args->index_count; i++) {
|
||||||
char *abs_path = abspath(args->indices[i]);
|
char *abs_path = abspath(args->indices[i]);
|
||||||
@@ -208,16 +211,20 @@ int main(int argc, const char *argv[]) {
|
|||||||
web_args_t *web_args = web_args_create();
|
web_args_t *web_args = web_args_create();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int arg_version = 0;
|
||||||
|
|
||||||
char * common_es_url = NULL;
|
char * common_es_url = NULL;
|
||||||
|
|
||||||
struct argparse_option options[] = {
|
struct argparse_option options[] = {
|
||||||
OPT_HELP(),
|
OPT_HELP(),
|
||||||
|
|
||||||
|
OPT_BOOLEAN('v', "version", &arg_version, "Show version and exit"),
|
||||||
|
|
||||||
OPT_GROUP("Scan options"),
|
OPT_GROUP("Scan options"),
|
||||||
OPT_INTEGER('t', "threads", &scan_args->threads, "Number of threads. DEFAULT=1"),
|
OPT_INTEGER('t', "threads", &scan_args->threads, "Number of threads. DEFAULT=1"),
|
||||||
OPT_FLOAT('q', "quality", &scan_args->quality,
|
OPT_FLOAT('q', "quality", &scan_args->quality,
|
||||||
"Thumbnail quality, on a scale of 1.0 to 31.0, 1.0 being the best. DEFAULT=15"),
|
"Thumbnail quality, on a scale of 1.0 to 31.0, 1.0 being the best. DEFAULT=5"),
|
||||||
OPT_INTEGER(0, "size", &scan_args->size, "Thumbnail size, in pixels. DEFAULT=200"),
|
OPT_INTEGER(0, "size", &scan_args->size, "Thumbnail size, in pixels. DEFAULT=500"),
|
||||||
OPT_INTEGER(0, "content-size", &scan_args->content_size,
|
OPT_INTEGER(0, "content-size", &scan_args->content_size,
|
||||||
"Number of bytes to be extracted from text documents. DEFAULT=4096"),
|
"Number of bytes to be extracted from text documents. DEFAULT=4096"),
|
||||||
OPT_STRING(0, "incremental", &scan_args->incremental,
|
OPT_STRING(0, "incremental", &scan_args->incremental,
|
||||||
@@ -225,11 +232,14 @@ int main(int argc, const char *argv[]) {
|
|||||||
OPT_STRING('o', "output", &scan_args->output, "Output directory. DEFAULT=index.sist2/"),
|
OPT_STRING('o', "output", &scan_args->output, "Output directory. DEFAULT=index.sist2/"),
|
||||||
OPT_STRING(0, "rewrite-url", &scan_args->rewrite_url, "Serve files from this url instead of from disk."),
|
OPT_STRING(0, "rewrite-url", &scan_args->rewrite_url, "Serve files from this url instead of from disk."),
|
||||||
OPT_STRING(0, "name", &scan_args->name, "Index display name. DEFAULT: (name of the directory)"),
|
OPT_STRING(0, "name", &scan_args->name, "Index display name. DEFAULT: (name of the directory)"),
|
||||||
|
OPT_INTEGER(0, "depth", &scan_args->depth, "Scan up to DEPTH subdirectories deep. "
|
||||||
|
"Use 0 to only scan files in PATH. DEFAULT: -1"),
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
#ifndef SIST_SCAN_ONLY
|
||||||
OPT_GROUP("Index options"),
|
OPT_GROUP("Index options"),
|
||||||
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT=http://localhost:9200"),
|
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT=http://localhost:9200"),
|
||||||
OPT_BOOLEAN('p', "print", &index_args->print, "Just print JSON documents to stdout."),
|
OPT_BOOLEAN('p', "print", &index_args->print, "Just print JSON documents to stdout."),
|
||||||
|
OPT_STRING(0, "script-file", &index_args->script_path, "Path to user script."),
|
||||||
OPT_BOOLEAN('f', "force-reset", &index_args->force_reset, "Reset Elasticsearch mappings and settings. "
|
OPT_BOOLEAN('f', "force-reset", &index_args->force_reset, "Reset Elasticsearch mappings and settings. "
|
||||||
"(You must use this option the first time you use the index command)"),
|
"(You must use this option the first time you use the index command)"),
|
||||||
|
|
||||||
@@ -237,6 +247,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT=http://localhost:9200"),
|
OPT_STRING(0, "es-url", &common_es_url, "Elasticsearch url. DEFAULT=http://localhost:9200"),
|
||||||
OPT_STRING(0, "bind", &web_args->bind, "Listen on this address. DEFAULT=localhost"),
|
OPT_STRING(0, "bind", &web_args->bind, "Listen on this address. DEFAULT=localhost"),
|
||||||
OPT_STRING(0, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
|
OPT_STRING(0, "port", &web_args->port, "Listen on this port. DEFAULT=4090"),
|
||||||
|
OPT_STRING(0, "auth", &web_args->credentials, "Basic auth in user:password format"),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OPT_END(),
|
OPT_END(),
|
||||||
@@ -247,6 +258,11 @@ int main(int argc, const char *argv[]) {
|
|||||||
argparse_describe(&argparse, DESCRIPTION, EPILOG);
|
argparse_describe(&argparse, DESCRIPTION, EPILOG);
|
||||||
argc = argparse_parse(&argparse, argc, argv);
|
argc = argparse_parse(&argparse, argc, argv);
|
||||||
|
|
||||||
|
if (arg_version) {
|
||||||
|
printf(Version);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef SIST_SCAN_ONLY
|
#ifndef SIST_SCAN_ONLY
|
||||||
web_args->es_url = common_es_url;
|
web_args->es_url = common_es_url;
|
||||||
index_args->es_url = common_es_url;
|
index_args->es_url = common_es_url;
|
||||||
|
|||||||
@@ -142,6 +142,9 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
if (library == NULL) {
|
if (library == NULL) {
|
||||||
FT_Init_FreeType(&library);
|
FT_Init_FreeType(&library);
|
||||||
}
|
}
|
||||||
|
if (buf == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FT_Face face;
|
FT_Face face;
|
||||||
FT_Error err = FT_New_Memory_Face(library, (unsigned char *) buf, buf_len, 0, &face);
|
FT_Error err = FT_New_Memory_Face(library, (unsigned char *) buf, buf_len, 0, &face);
|
||||||
|
|||||||
@@ -116,9 +116,9 @@ AVFrame *read_frame(AVFormatContext *pFormatCtx, AVCodecContext *decoder, int st
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define APPEND_TAG_META(doc, tag, keyname) \
|
#define APPEND_TAG_META(doc, tag_, keyname) \
|
||||||
text_buffer_t tex = text_buffer_create(-1); \
|
text_buffer_t tex = text_buffer_create(-1); \
|
||||||
text_buffer_append_string0(&tex, tag->value); \
|
text_buffer_append_string0(&tex, tag_->value); \
|
||||||
meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
|
meta_line_t *meta_tag = malloc(sizeof(meta_line_t) + tex.dyn_buffer.cur); \
|
||||||
meta_tag->key = keyname; \
|
meta_tag->key = keyname; \
|
||||||
strcpy(meta_tag->strval, tex.dyn_buffer.buf); \
|
strcpy(meta_tag->strval, tex.dyn_buffer.buf); \
|
||||||
@@ -151,30 +151,39 @@ void append_audio_meta(AVFormatContext *pFormatCtx, document_t *doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
void append_video_meta(AVFormatContext *pFormatCtx, document_t *doc, int include_audio_tags) {
|
void append_video_meta(AVFormatContext *pFormatCtx, AVFrame *frame, document_t *doc, int include_audio_tags, int is_video) {
|
||||||
|
|
||||||
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
if (is_video) {
|
||||||
meta_duration->key = MetaMediaDuration;
|
meta_line_t *meta_duration = malloc(sizeof(meta_line_t));
|
||||||
meta_duration->longval = pFormatCtx->duration / AV_TIME_BASE;
|
meta_duration->key = MetaMediaDuration;
|
||||||
APPEND_META(doc, meta_duration)
|
meta_duration->longval = pFormatCtx->duration / AV_TIME_BASE;
|
||||||
|
APPEND_META(doc, meta_duration)
|
||||||
|
|
||||||
meta_line_t *meta_bitrate = malloc(sizeof(meta_line_t));
|
meta_line_t *meta_bitrate = malloc(sizeof(meta_line_t));
|
||||||
meta_bitrate->key = MetaMediaBitrate;
|
meta_bitrate->key = MetaMediaBitrate;
|
||||||
meta_bitrate->longval = pFormatCtx->bit_rate;
|
meta_bitrate->longval = pFormatCtx->bit_rate;
|
||||||
APPEND_META(doc, meta_bitrate)
|
APPEND_META(doc, meta_bitrate)
|
||||||
|
}
|
||||||
|
|
||||||
AVDictionaryEntry *tag = NULL;
|
AVDictionaryEntry *tag = NULL;
|
||||||
while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
if (is_video) {
|
||||||
char key[32];
|
while ((tag = av_dict_get(pFormatCtx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||||
strncpy(key, tag->key, sizeof(key));
|
if (include_audio_tags && strcmp(tag->key, "title") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaTitle)
|
||||||
char *ptr = key;
|
} else if (strcmp(tag->key, "comment") == 0) {
|
||||||
for (; *ptr; ++ptr) *ptr = (char) tolower(*ptr);
|
APPEND_TAG_META(doc, tag, MetaContent)
|
||||||
|
} else if (include_audio_tags && strcmp(tag->key, "artist") == 0) {
|
||||||
if (strcmp(key, "title") == 0 && include_audio_tags) {
|
APPEND_TAG_META(doc, tag, MetaArtist)
|
||||||
APPEND_TAG_META(doc, tag, MetaTitle)
|
}
|
||||||
} else if (strcmp(key, "comment") == 0) {
|
}
|
||||||
APPEND_TAG_META(doc, tag, MetaContent)
|
} else {
|
||||||
|
// EXIF metadata
|
||||||
|
while ((tag = av_dict_get(frame->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||||
|
if (include_audio_tags && strcmp(tag->key, "Artist") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaArtist)
|
||||||
|
} else if (strcmp(tag->key, "ImageDescription") == 0) {
|
||||||
|
APPEND_TAG_META(doc, tag, MetaContent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,11 +245,6 @@ void parse_media(const char *filepath, document_t *doc) {
|
|||||||
if (video_stream != -1) {
|
if (video_stream != -1) {
|
||||||
AVStream *stream = pFormatCtx->streams[video_stream];
|
AVStream *stream = pFormatCtx->streams[video_stream];
|
||||||
|
|
||||||
if (stream->nb_frames > 1) {
|
|
||||||
//This is a video (not a still image)
|
|
||||||
append_video_meta(pFormatCtx, doc, audio_stream == -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stream->codecpar->width <= MIN_SIZE || stream->codecpar->height <= MIN_SIZE) {
|
if (stream->codecpar->width <= MIN_SIZE || stream->codecpar->height <= MIN_SIZE) {
|
||||||
avformat_close_input(&pFormatCtx);
|
avformat_close_input(&pFormatCtx);
|
||||||
avformat_free_context(pFormatCtx);
|
avformat_free_context(pFormatCtx);
|
||||||
@@ -273,6 +277,8 @@ void parse_media(const char *filepath, document_t *doc) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append_video_meta(pFormatCtx, frame, doc, audio_stream == -1, stream->nb_frames > 1);
|
||||||
|
|
||||||
// Scale frame
|
// Scale frame
|
||||||
AVFrame *scaled_frame = scale_frame(decoder, frame, ScanCtx.tn_size);
|
AVFrame *scaled_frame = scale_frame(decoder, frame, ScanCtx.tn_size);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ void *read_all(parse_job_t *job, const char *buf, int bytes_read, int *fd) {
|
|||||||
if (*fd == -1) {
|
if (*fd == -1) {
|
||||||
perror("open");
|
perror("open");
|
||||||
printf("%s\n", job->filepath);
|
printf("%s\n", job->filepath);
|
||||||
free(job);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +24,7 @@ void *read_all(parse_job_t *job, const char *buf, int bytes_read, int *fd) {
|
|||||||
int ret = read(*fd, full_buf + bytes_read, job->info.st_size - bytes_read);
|
int ret = read(*fd, full_buf + bytes_read, job->info.st_size - bytes_read);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
perror("read");
|
perror("read");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ void parse(void *arg) {
|
|||||||
void *pdf_buf = read_all(job, (char *) buf, bytes_read, &fd);
|
void *pdf_buf = read_all(job, (char *) buf, bytes_read, &fd);
|
||||||
parse_pdf(pdf_buf, doc.size, &doc);
|
parse_pdf(pdf_buf, doc.size, &doc);
|
||||||
|
|
||||||
if (pdf_buf != buf) {
|
if (pdf_buf != buf && pdf_buf != NULL) {
|
||||||
free(pdf_buf);
|
free(pdf_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ void parse(void *arg) {
|
|||||||
void *font_buf = read_all(job, (char *) buf, bytes_read, &fd);
|
void *font_buf = read_all(job, (char *) buf, bytes_read, &fd);
|
||||||
parse_font(font_buf, doc.size, &doc);
|
parse_font(font_buf, doc.size, &doc);
|
||||||
|
|
||||||
if (font_buf != buf) {
|
if (font_buf != buf && font_buf != NULL) {
|
||||||
free(font_buf);
|
free(font_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,10 @@ int read_stext_block(fz_stext_block *block, text_buffer_t *tex) {
|
|||||||
|
|
||||||
void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
void parse_pdf(void *buf, size_t buf_len, document_t *doc) {
|
||||||
|
|
||||||
|
if (buf == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
static int mu_is_initialized = 0;
|
static int mu_is_initialized = 0;
|
||||||
if (!mu_is_initialized) {
|
if (!mu_is_initialized) {
|
||||||
pthread_mutex_init(&ScanCtx.mupdf_mu, NULL);
|
pthread_mutex_init(&ScanCtx.mupdf_mu, NULL);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include <onion/handler.h>
|
#include <onion/handler.h>
|
||||||
#include <onion/block.h>
|
#include <onion/block.h>
|
||||||
#include <onion/shortcuts.h>
|
#include <onion/shortcuts.h>
|
||||||
|
#include <onion/codecs.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@
|
|||||||
#include "src/index/elastic.h"
|
#include "src/index/elastic.h"
|
||||||
#include "index/web.h"
|
#include "index/web.h"
|
||||||
#include "web/serve.h"
|
#include "web/serve.h"
|
||||||
|
#include "web/auth_basic.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|||||||
17
src/tpool.c
17
src/tpool.c
@@ -114,12 +114,18 @@ static void *tpool_worker(void *arg) {
|
|||||||
pthread_mutex_unlock(&(pool->work_mutex));
|
pthread_mutex_unlock(&(pool->work_mutex));
|
||||||
|
|
||||||
if (work != NULL) {
|
if (work != NULL) {
|
||||||
|
if (pool->stop) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
work->func(work->arg);
|
work->func(work->arg);
|
||||||
free(work);
|
free(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_lock(&(pool->work_mutex));
|
pthread_mutex_lock(&(pool->work_mutex));
|
||||||
pool->done_cnt++;
|
if (work != NULL) {
|
||||||
|
pool->done_cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
progress_bar_print((double) pool->done_cnt / pool->work_cnt, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
progress_bar_print((double) pool->done_cnt / pool->work_cnt, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
||||||
|
|
||||||
@@ -142,11 +148,14 @@ void tpool_wait(tpool_t *pool) {
|
|||||||
if (pool->done_cnt < pool->work_cnt) {
|
if (pool->done_cnt < pool->work_cnt) {
|
||||||
pthread_cond_wait(&(pool->working_cond), &(pool->work_mutex));
|
pthread_cond_wait(&(pool->working_cond), &(pool->work_mutex));
|
||||||
} else {
|
} else {
|
||||||
pool->stop = 1;
|
usleep(500000);
|
||||||
break;
|
if (pool->done_cnt == pool->work_cnt) {
|
||||||
|
pool->stop = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
progress_bar_print(100.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
|
||||||
}
|
}
|
||||||
|
progress_bar_print(1.0, ScanCtx.stat_tn_size, ScanCtx.stat_index_size);
|
||||||
pthread_mutex_unlock(&(pool->work_mutex));
|
pthread_mutex_unlock(&(pool->work_mutex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/util.c
16
src/util.c
@@ -90,7 +90,7 @@ void text_buffer_terminate_string(text_buffer_t *buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
int utf8_validchr(const char* s) {
|
int utf8_validchr(const char *s) {
|
||||||
if (0x00 == (0x80 & *s)) {
|
if (0x00 == (0x80 & *s)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else if (0xf0 == (0xf8 & *s)) {
|
} else if (0xf0 == (0xf8 & *s)) {
|
||||||
@@ -130,7 +130,7 @@ int utf8_validchr(const char* s) {
|
|||||||
if (0 == (0x1e & s[0])) {
|
if (0 == (0x1e & s[0])) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,12 +140,22 @@ int utf8_validchr(const char* s) {
|
|||||||
int text_buffer_append_string(text_buffer_t *buf, char *str, size_t len) {
|
int text_buffer_append_string(text_buffer_t *buf, char *str, size_t len) {
|
||||||
|
|
||||||
utf8_int32_t c;
|
utf8_int32_t c;
|
||||||
for (void *v = utf8codepoint(str, &c); c != '\0' && ((char*)v - str + 4) < len; v = utf8codepoint(v, &c)) {
|
if (str == NULL || len < 1 ||
|
||||||
|
(0xf0 == (0xf8 & str[0]) && len < 4) ||
|
||||||
|
(0xe0 == (0xf0 & str[0]) && len < 3) ||
|
||||||
|
(0xc0 == (0xe0 & str[0]) && len == 1) ||
|
||||||
|
*(str) == 0) {
|
||||||
|
text_buffer_terminate_string(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (void *v = utf8codepoint(str, &c); c != '\0' && ((char *) v - str + 4) < len; v = utf8codepoint(v, &c)) {
|
||||||
if (utf8_validchr(v)) {
|
if (utf8_validchr(v)) {
|
||||||
text_buffer_append_char(buf, c);
|
text_buffer_append_char(buf, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
text_buffer_terminate_string(buf);
|
text_buffer_terminate_string(buf);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int text_buffer_append_string0(text_buffer_t *buf, char *str) {
|
int text_buffer_append_string0(text_buffer_t *buf, char *str) {
|
||||||
|
|||||||
59
src/web/auth_basic.c
Normal file
59
src/web/auth_basic.c
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "auth_basic.h"
|
||||||
|
|
||||||
|
#define UNAUTHORIZED_TEXT "Unauthorized"
|
||||||
|
|
||||||
|
typedef struct auth_basic_data {
|
||||||
|
onion_handler *inside;
|
||||||
|
const char *b64credentials;
|
||||||
|
} auth_basic_data_t;
|
||||||
|
|
||||||
|
|
||||||
|
int authenticate(const char *expected, const char *credentials) {
|
||||||
|
|
||||||
|
if (expected == NULL) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (credentials && strncmp(credentials, "Basic ", 6) == 0) {
|
||||||
|
if (strcmp((credentials + 6), expected) == 0) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int auth_basic_handler(auth_basic_data_t *d,
|
||||||
|
onion_request *req,
|
||||||
|
onion_response *res) {
|
||||||
|
|
||||||
|
const char *credentials = onion_request_get_header(req, "Authorization");
|
||||||
|
|
||||||
|
if (authenticate(d->b64credentials, credentials)) {
|
||||||
|
return onion_handler_handle(d->inside, req, res);
|
||||||
|
}
|
||||||
|
|
||||||
|
onion_response_set_header(res, "WWW-Authenticate", "Basic realm=\"sist2\"");
|
||||||
|
onion_response_set_code(res, HTTP_UNAUTHORIZED);
|
||||||
|
onion_response_write(res, UNAUTHORIZED_TEXT, sizeof(UNAUTHORIZED_TEXT));
|
||||||
|
onion_response_set_length(res, sizeof(UNAUTHORIZED_TEXT));
|
||||||
|
|
||||||
|
return OCS_PROCESSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void auth_basic_free(auth_basic_data_t *data) {
|
||||||
|
onion_handler_free(data->inside);
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
onion_handler *auth_basic(const char *b64credentials, onion_handler *inside_level) {
|
||||||
|
|
||||||
|
auth_basic_data_t *privdata = malloc(sizeof(auth_basic_data_t));
|
||||||
|
|
||||||
|
privdata->b64credentials = b64credentials;
|
||||||
|
privdata->inside = inside_level;
|
||||||
|
|
||||||
|
return onion_handler_new((onion_handler_handler) auth_basic_handler, privdata,
|
||||||
|
(onion_handler_private_data_free) auth_basic_free);
|
||||||
|
}
|
||||||
|
|
||||||
4
src/web/auth_basic.h
Normal file
4
src/web/auth_basic.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#include "src/sist.h"
|
||||||
|
|
||||||
|
|
||||||
|
onion_handler *auth_basic(const char *b64credentials, onion_handler *inside_level);
|
||||||
@@ -245,6 +245,8 @@ int search(void *p, onion_request *req, onion_response *res) {
|
|||||||
|
|
||||||
if (r->status_code == 200) {
|
if (r->status_code == 200) {
|
||||||
onion_response_write(res, r->body, r->size);
|
onion_response_write(res, r->body, r->size);
|
||||||
|
} else {
|
||||||
|
onion_response_set_code(res, HTTP_INTERNAL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
free_response(r);
|
free_response(r);
|
||||||
@@ -391,9 +393,11 @@ void serve(const char *hostname, const char *port) {
|
|||||||
onion_set_hostname(o, hostname);
|
onion_set_hostname(o, hostname);
|
||||||
onion_set_port(o, port);
|
onion_set_port(o, port);
|
||||||
|
|
||||||
onion_url *urls = onion_root_url(o);
|
onion_url *urls = onion_url_new();
|
||||||
|
|
||||||
// Static paths
|
// Static paths
|
||||||
|
onion_set_root_handler(o, auth_basic(WebCtx.b64credentials, onion_url_to_handler(urls)));
|
||||||
|
|
||||||
onion_url_add(urls, "", search_index);
|
onion_url_add(urls, "", search_index);
|
||||||
onion_url_add(urls, "css", style);
|
onion_url_add(urls, "css", style);
|
||||||
onion_url_add(urls, "js", javascript);
|
onion_url_add(urls, "js", javascript);
|
||||||
@@ -410,6 +414,7 @@ void serve(const char *hostname, const char *port) {
|
|||||||
onion_url_add(urls, "^f/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", file);
|
onion_url_add(urls, "^f/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})$", file);
|
||||||
onion_url_add(urls, "i", index_info);
|
onion_url_add(urls, "i", index_info);
|
||||||
|
|
||||||
|
|
||||||
printf("Starting web server @ http://%s:%s\n", hostname, port);
|
printf("Starting web server @ http://%s:%s\n", hostname, port);
|
||||||
|
|
||||||
onion_listen(o);
|
onion_listen(o);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
109
web/css/dark.css
109
web/css/dark.css
@@ -1,3 +1,7 @@
|
|||||||
|
*:focus {
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #00BCD4;
|
color: #00BCD4;
|
||||||
}
|
}
|
||||||
@@ -19,6 +23,20 @@ body {
|
|||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
background: #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
|
||||||
|
border-top: 1px solid #424242;
|
||||||
|
border-bottom: none;
|
||||||
|
border-left: none;
|
||||||
|
border-right: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item:first-child {
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar-brand {
|
.navbar-brand {
|
||||||
font-size: 1.75rem;
|
font-size: 1.75rem;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
@@ -89,12 +107,18 @@ body {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
color: #00BCD4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.badge {
|
.badge {
|
||||||
margin-right: 3px;
|
margin-right: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.badge-user {
|
||||||
|
color: #212529;
|
||||||
|
background-color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
.fit {
|
.fit {
|
||||||
display: block;
|
display: block;
|
||||||
min-width: 64px;
|
min-width: 64px;
|
||||||
@@ -106,6 +130,15 @@ body {
|
|||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fit-sm {
|
||||||
|
display: block;
|
||||||
|
max-width: 64px;
|
||||||
|
max-height: 64px;
|
||||||
|
margin: 0 auto 0;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.audio-fit {
|
.audio-fit {
|
||||||
height: 39px;
|
height: 39px;
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
@@ -149,6 +182,8 @@ mark {
|
|||||||
border: 1px solid #616161;
|
border: 1px solid #616161;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin: 3px;
|
margin: 3px;
|
||||||
|
white-space: normal;
|
||||||
|
color: rgb(224, 224, 224);
|
||||||
}
|
}
|
||||||
|
|
||||||
.irs-single, .irs-from, .irs-to {
|
.irs-single, .irs-from, .irs-to {
|
||||||
@@ -164,6 +199,7 @@ mark {
|
|||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-select {
|
.custom-select {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
background-color: #37474F;
|
background-color: #37474F;
|
||||||
@@ -229,6 +265,7 @@ option {
|
|||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
background: #212121;
|
background: #212121;
|
||||||
color: #eee;
|
color: #eee;
|
||||||
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-xs {
|
.btn-xs {
|
||||||
@@ -240,3 +277,75 @@ option {
|
|||||||
.btn {
|
.btn {
|
||||||
color: #eee;
|
color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-link {
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-item.show .nav-link, .nav-tabs .nav-link.active {
|
||||||
|
background-color: #212121;
|
||||||
|
border-color: #616161 #616161 #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-link:focus, .nav-tabs .nav-link:focus {
|
||||||
|
border-color: #616161 #616161 #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs .nav-link:focus, .nav-tabs .nav-link:hover {
|
||||||
|
border-color: #e0e0e0 #e0e0e0 #212121;
|
||||||
|
color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs {
|
||||||
|
border-bottom: #616161;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 800px) {
|
||||||
|
#treeTabs {
|
||||||
|
flex-basis: inherit;
|
||||||
|
flex-grow: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
padding: .25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrapper-sm {
|
||||||
|
min-width: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tagline {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.version {
|
||||||
|
color: #00BCD4;
|
||||||
|
margin-left: -18px;
|
||||||
|
margin-top: -14px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
body {overflow-y:scroll;}
|
*:focus {
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
.progress {
|
.progress {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
@@ -6,15 +12,19 @@ body {overflow-y:scroll;}
|
|||||||
|
|
||||||
.card {
|
.card {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
box-shadow: 0 .125rem .25rem rgba(0,0,0,.075) !important;
|
box-shadow: 0 .125rem .25rem rgba(0, 0, 0, .075) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar-brand {
|
.navbar-brand {
|
||||||
font-size: 1.75rem;
|
font-size: 1.75rem;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.navbar {
|
.navbar {
|
||||||
background: #F7F7F7; border-bottom: solid 1px #dfdfdf;
|
background: #F7F7F7;
|
||||||
|
border-bottom: solid 1px #dfdfdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
.document {
|
.document {
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
}
|
}
|
||||||
@@ -47,6 +57,11 @@ body {overflow-y:scroll;}
|
|||||||
background-color: #FFC107;
|
background-color: #FFC107;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.badge-user {
|
||||||
|
color: #212529;
|
||||||
|
background-color: #e0e0e0;
|
||||||
|
}
|
||||||
|
|
||||||
.badge-text {
|
.badge-text {
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
background-color: #FAAB3C;
|
background-color: #FAAB3C;
|
||||||
@@ -84,6 +99,15 @@ body {overflow-y:scroll;}
|
|||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fit-sm {
|
||||||
|
display: block;
|
||||||
|
max-width: 64px;
|
||||||
|
max-height: 64px;
|
||||||
|
margin: 0 auto 0;
|
||||||
|
width: auto;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.audio-fit {
|
.audio-fit {
|
||||||
height: 39px;
|
height: 39px;
|
||||||
vertical-align: bottom;
|
vertical-align: bottom;
|
||||||
@@ -98,16 +122,17 @@ body {overflow-y:scroll;}
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 1500px) {
|
@media (min-width: 1500px) {
|
||||||
.container {
|
.container {
|
||||||
max-width: 1440px;
|
max-width: 1440px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-columns {
|
.card-columns {
|
||||||
column-count: 5;
|
column-count: 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 1800px) {
|
@media (min-width: 1800px) {
|
||||||
.container {
|
.container {
|
||||||
max-width: 1550px;
|
max-width: 1550px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,13 +144,15 @@ mark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.content-div {
|
.content-div {
|
||||||
font-family: SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
|
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
background-color: #f5f5f5;
|
background-color: #f5f5f5;
|
||||||
border: 1px solid #ccc;
|
border: 1px solid #ccc;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
margin: 3px;
|
margin: 3px;
|
||||||
|
white-space: normal;
|
||||||
|
color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.irs-single, .irs-from, .irs-to {
|
.irs-single, .irs-from, .irs-to {
|
||||||
@@ -145,8 +172,7 @@ mark {
|
|||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inspire-tree .selected > .wholerow, .inspire-tree .selected > .title-wrap:hover + .wholerow
|
.inspire-tree .selected > .wholerow, .inspire-tree .selected > .title-wrap:hover + .wholerow {
|
||||||
{
|
|
||||||
background: none;
|
background: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +188,7 @@ mark {
|
|||||||
line-height: 1rem;
|
line-height: 1rem;
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
background: #f8f9fa;
|
background: #f8f9fa;
|
||||||
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-xs {
|
.btn-xs {
|
||||||
@@ -169,3 +196,51 @@ mark {
|
|||||||
font-size: .875rem;
|
font-size: .875rem;
|
||||||
border-radius: .2rem;
|
border-radius: .2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nav {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 800px) {
|
||||||
|
#treeTabs {
|
||||||
|
flex-basis: inherit;
|
||||||
|
flex-grow: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group {
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
padding: .25rem 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrapper-sm {
|
||||||
|
min-width: 64px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.media-expanded .fit {
|
||||||
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tagline {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.version {
|
||||||
|
color: #007bff;
|
||||||
|
margin-left: -18px;
|
||||||
|
margin-top: -14px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|||||||
325
web/js/dom.js
325
web/js/dom.js
@@ -75,6 +75,84 @@ function shouldPlayVideo(hit) {
|
|||||||
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makePlaceholder(w, h, small) {
|
||||||
|
let calc;
|
||||||
|
if (small) {
|
||||||
|
calc = w > h
|
||||||
|
? (64 / w / h) >= 100
|
||||||
|
? (64 * w / h)
|
||||||
|
: 64
|
||||||
|
: 64;
|
||||||
|
} else {
|
||||||
|
calc = w > h
|
||||||
|
? (175 / w / h) >= 272
|
||||||
|
? (175 * w / h)
|
||||||
|
: 175
|
||||||
|
: 175;
|
||||||
|
}
|
||||||
|
|
||||||
|
const el = document.createElement("div");
|
||||||
|
el.setAttribute("style", `height: ${calc}px`);
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeTitle(hit) {
|
||||||
|
let title = document.createElement("div");
|
||||||
|
title.setAttribute("class", "file-title");
|
||||||
|
let extension = hit["_source"].hasOwnProperty("extension") && hit["_source"]["extension"] !== "" ? "." + hit["_source"]["extension"] : "";
|
||||||
|
|
||||||
|
applyNameToTitle(hit, title, extension);
|
||||||
|
|
||||||
|
title.setAttribute("title", hit["_source"]["path"] + "/" + hit["_source"]["name"] + extension);
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTags(hit, mimeCategory) {
|
||||||
|
|
||||||
|
let tags = [];
|
||||||
|
switch (mimeCategory) {
|
||||||
|
case "video":
|
||||||
|
case "image":
|
||||||
|
if (hit["_source"].hasOwnProperty("videoc")) {
|
||||||
|
const formatTag = document.createElement("span");
|
||||||
|
formatTag.setAttribute("class", "badge badge-pill badge-video");
|
||||||
|
formatTag.appendChild(document.createTextNode(hit["_source"]["videoc"].replace(" ", "")));
|
||||||
|
tags.push(formatTag);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "audio": {
|
||||||
|
if (hit["_source"].hasOwnProperty("audioc")) {
|
||||||
|
let formatTag = document.createElement("span");
|
||||||
|
formatTag.setAttribute("class", "badge badge-pill badge-audio");
|
||||||
|
formatTag.appendChild(document.createTextNode(hit["_source"]["audioc"]));
|
||||||
|
tags.push(formatTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// User tags
|
||||||
|
if (hit["_source"].hasOwnProperty("tag")) {
|
||||||
|
hit["_source"]["tag"].forEach(tag => {
|
||||||
|
const userTag = document.createElement("span");
|
||||||
|
userTag.setAttribute("class", "badge badge-pill badge-user");
|
||||||
|
|
||||||
|
const tokens = tag.split("#");
|
||||||
|
|
||||||
|
if (tokens.length > 1) {
|
||||||
|
const bg = "#" + tokens[1];
|
||||||
|
const fg = lum(tokens[1]) > 40 ? "#000" : "#fff";
|
||||||
|
userTag.setAttribute("style", `background-color: ${bg}; color: ${fg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = tokens[0].split(".")[tokens[0].split(".").length - 1];
|
||||||
|
userTag.appendChild(document.createTextNode(name));
|
||||||
|
tags.push(userTag);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param hit
|
* @param hit
|
||||||
@@ -92,22 +170,13 @@ function createDocCard(hit) {
|
|||||||
link.setAttribute("target", "_blank");
|
link.setAttribute("target", "_blank");
|
||||||
|
|
||||||
//Title
|
//Title
|
||||||
let title = document.createElement("p");
|
let title = makeTitle(hit);
|
||||||
title.setAttribute("class", "file-title");
|
|
||||||
let extension = hit["_source"].hasOwnProperty("extension") && hit["_source"]["extension"] !== "" ? "." + hit["_source"]["extension"] : "";
|
|
||||||
|
|
||||||
applyNameToTitle(hit, title, extension);
|
|
||||||
|
|
||||||
title.setAttribute("title", hit["_source"]["path"] + "/" + hit["_source"]["name"] + extension);
|
|
||||||
docCard.appendChild(title);
|
|
||||||
|
|
||||||
let tagContainer = document.createElement("div");
|
let tagContainer = document.createElement("div");
|
||||||
tagContainer.setAttribute("class", "card-text");
|
tagContainer.setAttribute("class", "card-text");
|
||||||
|
|
||||||
if (hit["_source"].hasOwnProperty("mime") && hit["_source"]["mime"] !== null) {
|
if (hit["_source"].hasOwnProperty("mime") && hit["_source"]["mime"] !== null) {
|
||||||
|
|
||||||
let tags = [];
|
|
||||||
let thumbnail = null;
|
|
||||||
let thumbnailOverlay = null;
|
let thumbnailOverlay = null;
|
||||||
let imgWrapper = document.createElement("div");
|
let imgWrapper = document.createElement("div");
|
||||||
imgWrapper.setAttribute("style", "position: relative");
|
imgWrapper.setAttribute("style", "position: relative");
|
||||||
@@ -115,28 +184,7 @@ function createDocCard(hit) {
|
|||||||
let mimeCategory = hit["_source"]["mime"].split("/")[0];
|
let mimeCategory = hit["_source"]["mime"].split("/")[0];
|
||||||
|
|
||||||
//Thumbnail
|
//Thumbnail
|
||||||
if (mimeCategory === "video" && shouldPlayVideo(hit)) {
|
let thumbnail = makeThumbnail(mimeCategory, hit, imgWrapper, false);
|
||||||
thumbnail = document.createElement("video");
|
|
||||||
addVidSrc("f/" + hit["_id"], hit["_source"]["mime"], thumbnail);
|
|
||||||
|
|
||||||
thumbnail.setAttribute("class", "fit");
|
|
||||||
thumbnail.setAttribute("loop", "");
|
|
||||||
thumbnail.setAttribute("controls", "");
|
|
||||||
thumbnail.setAttribute("preload", "none");
|
|
||||||
thumbnail.setAttribute("poster", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
|
||||||
thumbnail.addEventListener("dblclick", function () {
|
|
||||||
thumbnail.webkitRequestFullScreen();
|
|
||||||
});
|
|
||||||
} else if ((hit["_source"].hasOwnProperty("width") && hit["_source"]["width"] > 20 && hit["_source"]["height"] > 20)
|
|
||||||
|| hit["_source"]["mime"] === "application/pdf"
|
|
||||||
|| hit["_source"]["mime"] === "application/epub+zip"
|
|
||||||
|| hit["_source"]["mime"] === "application/x-cbz"
|
|
||||||
|| hit["_source"].hasOwnProperty("font_name")
|
|
||||||
) {
|
|
||||||
thumbnail = document.createElement("img");
|
|
||||||
thumbnail.setAttribute("class", "card-img-top fit");
|
|
||||||
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Thumbnail overlay
|
//Thumbnail overlay
|
||||||
switch (mimeCategory) {
|
switch (mimeCategory) {
|
||||||
@@ -164,46 +212,29 @@ function createDocCard(hit) {
|
|||||||
if (hit["_source"].hasOwnProperty("duration")) {
|
if (hit["_source"].hasOwnProperty("duration")) {
|
||||||
thumbnailOverlay = document.createElement("div");
|
thumbnailOverlay = document.createElement("div");
|
||||||
thumbnailOverlay.setAttribute("class", "card-img-overlay");
|
thumbnailOverlay.setAttribute("class", "card-img-overlay");
|
||||||
let durationBadge = document.createElement("span");
|
const durationBadge = document.createElement("span");
|
||||||
durationBadge.setAttribute("class", "badge badge-resolution");
|
durationBadge.setAttribute("class", "badge badge-resolution");
|
||||||
durationBadge.appendChild(document.createTextNode(humanTime(hit["_source"]["duration"])));
|
durationBadge.appendChild(document.createTextNode(humanTime(hit["_source"]["duration"])));
|
||||||
thumbnailOverlay.appendChild(durationBadge);
|
thumbnailOverlay.appendChild(durationBadge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Tags
|
// Tags
|
||||||
switch (mimeCategory) {
|
let tags = getTags(hit, mimeCategory);
|
||||||
case "video":
|
for (let i = 0; i < tags.length; i++) {
|
||||||
case "image":
|
tagContainer.appendChild(tags[i]);
|
||||||
if (hit["_source"].hasOwnProperty("videoc")) {
|
|
||||||
let formatTag = document.createElement("span");
|
|
||||||
formatTag.setAttribute("class", "badge badge-pill badge-video");
|
|
||||||
formatTag.appendChild(document.createTextNode(hit["_source"]["videoc"].replace(" ", "")));
|
|
||||||
tags.push(formatTag);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "audio": {
|
|
||||||
if (hit["_source"].hasOwnProperty("audioc")) {
|
|
||||||
let formatTag = document.createElement("span");
|
|
||||||
formatTag.setAttribute("class", "badge badge-pill badge-audio");
|
|
||||||
formatTag.appendChild(document.createTextNode(hit["_source"]["audioc"]));
|
|
||||||
tags.push(formatTag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Content
|
//Content
|
||||||
let contentHl = getContentHighlight(hit);
|
let contentHl = getContentHighlight(hit);
|
||||||
if (contentHl !== undefined) {
|
if (contentHl !== undefined) {
|
||||||
let contentDiv = document.createElement("div");
|
const contentDiv = document.createElement("div");
|
||||||
contentDiv.setAttribute("class", "content-div");
|
contentDiv.setAttribute("class", "content-div");
|
||||||
contentDiv.insertAdjacentHTML('afterbegin', contentHl);
|
contentDiv.insertAdjacentHTML('afterbegin', contentHl);
|
||||||
docCard.appendChild(contentDiv);
|
docCard.appendChild(contentDiv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thumbnail !== null) {
|
if (thumbnail !== null) {
|
||||||
imgWrapper.appendChild(thumbnail);
|
|
||||||
docCard.appendChild(imgWrapper);
|
docCard.appendChild(imgWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,10 +254,6 @@ function createDocCard(hit) {
|
|||||||
if (thumbnailOverlay !== null) {
|
if (thumbnailOverlay !== null) {
|
||||||
imgWrapper.appendChild(thumbnailOverlay);
|
imgWrapper.appendChild(thumbnailOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < tags.length; i++) {
|
|
||||||
tagContainer.appendChild(tags[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Size tag
|
//Size tag
|
||||||
@@ -244,6 +271,139 @@ function createDocCard(hit) {
|
|||||||
return docCard;
|
return docCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeThumbnail(mimeCategory, hit, imgWrapper, small) {
|
||||||
|
let thumbnail;
|
||||||
|
|
||||||
|
if (mimeCategory === "video" && shouldPlayVideo(hit)) {
|
||||||
|
thumbnail = document.createElement("video");
|
||||||
|
addVidSrc("f/" + hit["_id"], hit["_source"]["mime"], thumbnail);
|
||||||
|
|
||||||
|
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"], small);
|
||||||
|
imgWrapper.appendChild(placeholder);
|
||||||
|
|
||||||
|
if (small) {
|
||||||
|
thumbnail.setAttribute("class", "fit-sm");
|
||||||
|
} else {
|
||||||
|
thumbnail.setAttribute("class", "fit");
|
||||||
|
}
|
||||||
|
if (small) {
|
||||||
|
thumbnail.style.cursor = "pointer";
|
||||||
|
thumbnail.title = "Enlarge";
|
||||||
|
thumbnail.addEventListener("click", function () {
|
||||||
|
imgWrapper.classList.remove("wrapper-sm", "mr-1");
|
||||||
|
imgWrapper.parentElement.classList.add("media-expanded");
|
||||||
|
thumbnail.setAttribute("class", "fit");
|
||||||
|
thumbnail.setAttribute("controls", "");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
thumbnail.setAttribute("controls", "");
|
||||||
|
}
|
||||||
|
thumbnail.setAttribute("preload", "none");
|
||||||
|
thumbnail.setAttribute("poster", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
|
thumbnail.addEventListener("dblclick", function () {
|
||||||
|
thumbnail.setAttribute("controls", "");
|
||||||
|
if (thumbnail.webkitRequestFullScreen) {
|
||||||
|
thumbnail.webkitRequestFullScreen();
|
||||||
|
} else {
|
||||||
|
thumbnail.requestFullscreen();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const poster = new Image();
|
||||||
|
poster.src = thumbnail.getAttribute('poster');
|
||||||
|
poster.addEventListener("load", function () {
|
||||||
|
placeholder.remove();
|
||||||
|
imgWrapper.appendChild(thumbnail);
|
||||||
|
});
|
||||||
|
} else if ((hit["_source"].hasOwnProperty("width") && hit["_source"]["width"] > 32 && hit["_source"]["height"] > 32)
|
||||||
|
|| hit["_source"]["mime"] === "application/pdf"
|
||||||
|
|| hit["_source"]["mime"] === "application/epub+zip"
|
||||||
|
|| hit["_source"]["mime"] === "application/x-cbz"
|
||||||
|
|| hit["_source"].hasOwnProperty("font_name")
|
||||||
|
) {
|
||||||
|
thumbnail = document.createElement("img");
|
||||||
|
if (small) {
|
||||||
|
thumbnail.setAttribute("class", "fit-sm");
|
||||||
|
} else {
|
||||||
|
thumbnail.setAttribute("class", "card-img-top fit");
|
||||||
|
}
|
||||||
|
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
|
|
||||||
|
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"], small);
|
||||||
|
imgWrapper.appendChild(placeholder);
|
||||||
|
|
||||||
|
thumbnail.addEventListener("error", () => {
|
||||||
|
imgWrapper.remove();
|
||||||
|
});
|
||||||
|
thumbnail.addEventListener("load", () => {
|
||||||
|
placeholder.remove();
|
||||||
|
imgWrapper.appendChild(thumbnail);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return thumbnail;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDocLine(hit) {
|
||||||
|
|
||||||
|
let mimeCategory = hit["_source"]["mime"].split("/")[0];
|
||||||
|
let tags = getTags(hit, mimeCategory);
|
||||||
|
|
||||||
|
let imgWrapper = document.createElement("div");
|
||||||
|
imgWrapper.setAttribute("class", "align-self-start mr-1 wrapper-sm");
|
||||||
|
|
||||||
|
let media = document.createElement("div");
|
||||||
|
media.setAttribute("class", "media");
|
||||||
|
|
||||||
|
const line = document.createElement("div");
|
||||||
|
line.setAttribute("class", "list-group-item flex-column align-items-start");
|
||||||
|
|
||||||
|
|
||||||
|
const title = makeTitle(hit);
|
||||||
|
|
||||||
|
let link = document.createElement("a");
|
||||||
|
link.setAttribute("href", "f/" + hit["_id"]);
|
||||||
|
link.setAttribute("target", "_blank");
|
||||||
|
link.appendChild(title);
|
||||||
|
|
||||||
|
const titleDiv = document.createElement("div");
|
||||||
|
titleDiv.setAttribute("class", "file-title");
|
||||||
|
titleDiv.appendChild(link);
|
||||||
|
|
||||||
|
line.appendChild(media);
|
||||||
|
|
||||||
|
let thumbnail = makeThumbnail(mimeCategory, hit, imgWrapper, true);
|
||||||
|
if (thumbnail) {
|
||||||
|
media.appendChild(imgWrapper);
|
||||||
|
}
|
||||||
|
media.appendChild(titleDiv);
|
||||||
|
|
||||||
|
// Content
|
||||||
|
let contentHl = getContentHighlight(hit);
|
||||||
|
if (contentHl !== undefined) {
|
||||||
|
const contentDiv = document.createElement("div");
|
||||||
|
contentDiv.setAttribute("class", "content-div");
|
||||||
|
contentDiv.insertAdjacentHTML('afterbegin', contentHl);
|
||||||
|
titleDiv.appendChild(contentDiv);
|
||||||
|
}
|
||||||
|
|
||||||
|
let tagContainer = document.createElement("div");
|
||||||
|
tagContainer.setAttribute("class", "");
|
||||||
|
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
|
tagContainer.appendChild(tags[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Size tag
|
||||||
|
let sizeTag = document.createElement("small");
|
||||||
|
sizeTag.appendChild(document.createTextNode(humanFileSize(hit["_source"]["size"])));
|
||||||
|
sizeTag.setAttribute("class", "text-muted");
|
||||||
|
tagContainer.appendChild(sizeTag);
|
||||||
|
|
||||||
|
titleDiv.appendChild(tagContainer);
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
function makePreloader() {
|
function makePreloader() {
|
||||||
const elem = document.createElement("div");
|
const elem = document.createElement("div");
|
||||||
elem.setAttribute("class", "progress");
|
elem.setAttribute("class", "progress");
|
||||||
@@ -268,18 +428,53 @@ function makePageIndicator(searchResult) {
|
|||||||
function makeStatsCard(searchResult) {
|
function makeStatsCard(searchResult) {
|
||||||
|
|
||||||
let statsCard = document.createElement("div");
|
let statsCard = document.createElement("div");
|
||||||
statsCard.setAttribute("class", "card");
|
statsCard.setAttribute("class", "card stat");
|
||||||
let statsCardBody = document.createElement("div");
|
let statsCardBody = document.createElement("div");
|
||||||
statsCardBody.setAttribute("class", "card-body");
|
statsCardBody.setAttribute("class", "card-body");
|
||||||
|
|
||||||
let stat = document.createElement("p");
|
const resultMode = document.createElement("div");
|
||||||
|
resultMode.setAttribute("class", "btn-group btn-group-toggle");
|
||||||
|
resultMode.setAttribute("data-toggle", "buttons");
|
||||||
|
resultMode.style.cssFloat = "right";
|
||||||
|
|
||||||
|
const listMode = document.createElement("label");
|
||||||
|
listMode.setAttribute("class", "btn btn-primary");
|
||||||
|
listMode.appendChild(document.createTextNode("List"));
|
||||||
|
|
||||||
|
const gridMode = document.createElement("label");
|
||||||
|
gridMode.setAttribute("class", "btn btn-primary");
|
||||||
|
gridMode.appendChild(document.createTextNode("Grid"));
|
||||||
|
|
||||||
|
resultMode.appendChild(gridMode);
|
||||||
|
resultMode.appendChild(listMode);
|
||||||
|
|
||||||
|
if (mode === "grid") {
|
||||||
|
gridMode.classList.add("active")
|
||||||
|
} else {
|
||||||
|
listMode.classList.add("active")
|
||||||
|
}
|
||||||
|
|
||||||
|
gridMode.addEventListener("click", () => {
|
||||||
|
mode = "grid";
|
||||||
|
localStorage.setItem("mode", mode);
|
||||||
|
searchDebounced();
|
||||||
|
});
|
||||||
|
listMode.addEventListener("click", () => {
|
||||||
|
mode = "list";
|
||||||
|
localStorage.setItem("mode", mode);
|
||||||
|
searchDebounced();
|
||||||
|
});
|
||||||
|
|
||||||
|
let stat = document.createElement("span");
|
||||||
const totalHits = searchResult["hits"]["total"].hasOwnProperty("value")
|
const totalHits = searchResult["hits"]["total"].hasOwnProperty("value")
|
||||||
? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"];
|
? searchResult["hits"]["total"]["value"] : searchResult["hits"]["total"];
|
||||||
stat.appendChild(document.createTextNode(totalHits + " results in " + searchResult["took"] + "ms"));
|
stat.appendChild(document.createTextNode(totalHits + " results in " + searchResult["took"] + "ms"));
|
||||||
|
|
||||||
statsCardBody.appendChild(stat);
|
statsCardBody.appendChild(stat);
|
||||||
|
statsCardBody.appendChild(resultMode);
|
||||||
|
|
||||||
if (totalHits !== 0) {
|
if (totalHits !== 0) {
|
||||||
let sizeStat = document.createElement("span");
|
let sizeStat = document.createElement("div");
|
||||||
sizeStat.appendChild(document.createTextNode(humanFileSize(searchResult["aggregations"]["total_size"]["value"])));
|
sizeStat.appendChild(document.createTextNode(humanFileSize(searchResult["aggregations"]["total_size"]["value"])));
|
||||||
statsCardBody.appendChild(sizeStat);
|
statsCardBody.appendChild(sizeStat);
|
||||||
}
|
}
|
||||||
@@ -291,7 +486,11 @@ function makeStatsCard(searchResult) {
|
|||||||
|
|
||||||
function makeResultContainer() {
|
function makeResultContainer() {
|
||||||
let resultContainer = document.createElement("div");
|
let resultContainer = document.createElement("div");
|
||||||
resultContainer.setAttribute("class", "card-columns");
|
|
||||||
|
|
||||||
|
if (mode === "grid") {
|
||||||
|
resultContainer.setAttribute("class", "card-columns");
|
||||||
|
} else {
|
||||||
|
resultContainer.setAttribute("class", "list-group");
|
||||||
|
}
|
||||||
return resultContainer;
|
return resultContainer;
|
||||||
}
|
}
|
||||||
|
|||||||
156
web/js/search.js
156
web/js/search.js
@@ -1,6 +1,8 @@
|
|||||||
const SIZE = 40;
|
const SIZE = 40;
|
||||||
let mimeMap = [];
|
let mimeMap = [];
|
||||||
let tree;
|
let tagMap = [];
|
||||||
|
let mimeTree;
|
||||||
|
let tagTree;
|
||||||
|
|
||||||
let searchBar = document.getElementById("searchBar");
|
let searchBar = document.getElementById("searchBar");
|
||||||
let pathBar = document.getElementById("pathBar");
|
let pathBar = document.getElementById("pathBar");
|
||||||
@@ -10,6 +12,13 @@ let coolingDown = false;
|
|||||||
let searchBusy = true;
|
let searchBusy = true;
|
||||||
let selectedIndices = [];
|
let selectedIndices = [];
|
||||||
|
|
||||||
|
let mode;
|
||||||
|
if (localStorage.getItem("mode") === null) {
|
||||||
|
mode = "grid";
|
||||||
|
} else {
|
||||||
|
mode = localStorage.getItem("mode")
|
||||||
|
}
|
||||||
|
|
||||||
jQuery["jsonPost"] = function (url, data) {
|
jQuery["jsonPost"] = function (url, data) {
|
||||||
return jQuery.ajax({
|
return jQuery.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
@@ -32,7 +41,7 @@ window.onload = () => {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
function toggleSearchBar() {
|
function toggleFuzzy() {
|
||||||
searchDebounced();
|
searchDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +58,23 @@ $.jsonPost("i").then(resp => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function handleTreeClick (tree) {
|
||||||
|
return (event, node, handler) => {
|
||||||
|
event.preventTreeDefault();
|
||||||
|
|
||||||
|
if (node.id === "any") {
|
||||||
|
if (!node.itree.state.checked) {
|
||||||
|
tree.deselect();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tree.node("any").deselect();
|
||||||
|
}
|
||||||
|
|
||||||
|
handler();
|
||||||
|
searchDebounced();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$.jsonPost("es", {
|
$.jsonPost("es", {
|
||||||
aggs: {
|
aggs: {
|
||||||
mimeTypes: {
|
mimeTypes: {
|
||||||
@@ -85,34 +111,86 @@ $.jsonPost("es", {
|
|||||||
});
|
});
|
||||||
mimeMap.push({"text": "All", "id": "any"});
|
mimeMap.push({"text": "All", "id": "any"});
|
||||||
|
|
||||||
tree = new InspireTree({
|
mimeTree = new InspireTree({
|
||||||
selection: {
|
selection: {
|
||||||
mode: 'checkbox'
|
mode: 'checkbox'
|
||||||
},
|
},
|
||||||
data: mimeMap
|
data: mimeMap
|
||||||
});
|
});
|
||||||
new InspireTreeDOM(tree, {
|
new InspireTreeDOM(mimeTree, {
|
||||||
target: '.tree'
|
target: '#mimeTree'
|
||||||
});
|
});
|
||||||
tree.on("node.click", function (event, node, handler) {
|
mimeTree.on("node.click", handleTreeClick(mimeTree));
|
||||||
event.preventTreeDefault();
|
mimeTree.select();
|
||||||
|
mimeTree.node("any").deselect();
|
||||||
|
});
|
||||||
|
|
||||||
if (node.id === "any") {
|
function leafTag(tag) {
|
||||||
if (!node.itree.state.checked) {
|
const tokens = tag.split(".");
|
||||||
tree.deselect();
|
return tokens[tokens.length-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tags tree
|
||||||
|
$.jsonPost("es", {
|
||||||
|
aggs: {
|
||||||
|
tags: {
|
||||||
|
terms: {
|
||||||
|
field: "tag",
|
||||||
|
size: 10000
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
tree.node("any").deselect();
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
handler();
|
size: 0,
|
||||||
searchDebounced();
|
}).then(resp => {
|
||||||
|
resp["aggregations"]["tags"]["buckets"]
|
||||||
|
.sort((a, b) => a["key"].localeCompare(b["key"]))
|
||||||
|
.forEach(bucket => {
|
||||||
|
addTag(tagMap, bucket["key"], bucket["key"], bucket["doc_count"])
|
||||||
});
|
});
|
||||||
tree.select();
|
|
||||||
tree.node("any").deselect();
|
tagMap.push({"text": "All", "id": "any"});
|
||||||
|
tagTree = new InspireTree({
|
||||||
|
selection: {
|
||||||
|
mode: 'checkbox'
|
||||||
|
},
|
||||||
|
data: tagMap
|
||||||
|
});
|
||||||
|
new InspireTreeDOM(tagTree, {
|
||||||
|
target: '#tagTree'
|
||||||
|
});
|
||||||
|
tagTree.on("node.click", handleTreeClick(tagTree));
|
||||||
|
tagTree.node("any").select();
|
||||||
searchBusy = false;
|
searchBusy = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function addTag(map, tag, id, count) {
|
||||||
|
let tags = tag.split("#")[0].split(".");
|
||||||
|
|
||||||
|
let child = {
|
||||||
|
id: id,
|
||||||
|
text: tags.length !== 1 ? tags[0] : `${tags[0]} (${count})`,
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
|
||||||
|
let found = false;
|
||||||
|
map.forEach(node => {
|
||||||
|
if (node.text === child.text) {
|
||||||
|
found = true;
|
||||||
|
if (tags.length !== 1) {
|
||||||
|
addTag(node.children, tags.slice(1).join("."), id, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!found) {
|
||||||
|
if (tags.length !== 1) {
|
||||||
|
addTag(child.children, tags.slice(1).join("."), id, count);
|
||||||
|
map.push(child);
|
||||||
|
} else {
|
||||||
|
map.push(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
new autoComplete({
|
new autoComplete({
|
||||||
selector: '#pathBar',
|
selector: '#pathBar',
|
||||||
minChars: 1,
|
minChars: 1,
|
||||||
@@ -140,7 +218,12 @@ new autoComplete({
|
|||||||
|
|
||||||
function insertHits(resultContainer, hits) {
|
function insertHits(resultContainer, hits) {
|
||||||
for (let i = 0; i < hits.length; i++) {
|
for (let i = 0; i < hits.length; i++) {
|
||||||
resultContainer.appendChild(createDocCard(hits[i]));
|
|
||||||
|
if (mode === "grid") {
|
||||||
|
resultContainer.appendChild(createDocCard(hits[i]));
|
||||||
|
} else {
|
||||||
|
resultContainer.appendChild(createDocLine(hits[i]));
|
||||||
|
}
|
||||||
docCount++;
|
docCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,8 +264,8 @@ function doScroll() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedMimeTypes() {
|
function getSelectedNodes(tree) {
|
||||||
let mimeTypes = [];
|
let selectedNodes = [];
|
||||||
|
|
||||||
let selected = tree.selected();
|
let selected = tree.selected();
|
||||||
|
|
||||||
@@ -194,11 +277,11 @@ function getSelectedMimeTypes() {
|
|||||||
|
|
||||||
//Only get children
|
//Only get children
|
||||||
if (selected[i].text.indexOf("(") !== -1) {
|
if (selected[i].text.indexOf("(") !== -1) {
|
||||||
mimeTypes.push(selected[i].id);
|
selectedNodes.push(selected[i].id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mimeTypes
|
return selectedNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
@@ -218,21 +301,37 @@ function search() {
|
|||||||
|
|
||||||
let query = searchBar.value;
|
let query = searchBar.value;
|
||||||
let empty = query === "";
|
let empty = query === "";
|
||||||
let condition = $("#barToggle").prop("checked") && !empty ? "must" : "should";
|
let condition = empty ? "should" : "must";
|
||||||
let filters = [
|
let filters = [
|
||||||
{range: {size: {gte: size_min, lte: size_max}}},
|
{range: {size: {gte: size_min, lte: size_max}}},
|
||||||
{terms: {index: selectedIndices}}
|
{terms: {index: selectedIndices}}
|
||||||
];
|
];
|
||||||
|
let fields = [
|
||||||
|
"name^8",
|
||||||
|
"content^3",
|
||||||
|
"album^8", "artist^8", "title^8", "genre^2", "album_artist^8",
|
||||||
|
"font_name^6"
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($("#fuzzyToggle").prop("checked")) {
|
||||||
|
fields.push("content.nGram");
|
||||||
|
fields.push("name.nGram^3");
|
||||||
|
}
|
||||||
|
|
||||||
let path = pathBar.value.replace(/\/$/, "").toLowerCase(); //remove trailing slashes
|
let path = pathBar.value.replace(/\/$/, "").toLowerCase(); //remove trailing slashes
|
||||||
if (path !== "") {
|
if (path !== "") {
|
||||||
filters.push([{term: {path: path}}])
|
filters.push([{term: {path: path}}])
|
||||||
}
|
}
|
||||||
let mimeTypes = getSelectedMimeTypes();
|
let mimeTypes = getSelectedNodes(mimeTree);
|
||||||
if (!mimeTypes.includes("any")) {
|
if (!mimeTypes.includes("any")) {
|
||||||
filters.push([{terms: {"mime": mimeTypes}}]);
|
filters.push([{terms: {"mime": mimeTypes}}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tags = getSelectedNodes(tagTree);
|
||||||
|
if (!tags.includes("any")) {
|
||||||
|
filters.push([{terms: {"tag": tags}}]);
|
||||||
|
}
|
||||||
|
|
||||||
$.jsonPost("es?scroll=1", {
|
$.jsonPost("es?scroll=1", {
|
||||||
"_source": {
|
"_source": {
|
||||||
excludes: ["content"]
|
excludes: ["content"]
|
||||||
@@ -243,12 +342,7 @@ function search() {
|
|||||||
multi_match: {
|
multi_match: {
|
||||||
query: query,
|
query: query,
|
||||||
type: "most_fields",
|
type: "most_fields",
|
||||||
fields: [
|
fields: fields,
|
||||||
"name^8", "name.nGram^3", "content^3",
|
|
||||||
"content.nGram",
|
|
||||||
"album^8", "artist^8", "title^8", "genre^2", "album_artist^8",
|
|
||||||
"font_name^6"
|
|
||||||
],
|
|
||||||
operator: "and"
|
operator: "and"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -265,7 +359,7 @@ function search() {
|
|||||||
content: {},
|
content: {},
|
||||||
name: {},
|
name: {},
|
||||||
"name.nGram": {},
|
"name.nGram": {},
|
||||||
// font_name: {},
|
font_name: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
aggs: {
|
aggs: {
|
||||||
|
|||||||
@@ -43,9 +43,9 @@ function humanTime(sec_num) {
|
|||||||
|
|
||||||
function debounce(func, wait) {
|
function debounce(func, wait) {
|
||||||
let timeout;
|
let timeout;
|
||||||
return function() {
|
return function () {
|
||||||
let context = this, args = arguments;
|
let context = this, args = arguments;
|
||||||
let later = function() {
|
let later = function () {
|
||||||
timeout = null;
|
timeout = null;
|
||||||
func.apply(context, args);
|
func.apply(context, args);
|
||||||
};
|
};
|
||||||
@@ -54,3 +54,13 @@ function debounce(func, wait) {
|
|||||||
func.apply(context, args);
|
func.apply(context, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lum(c) {
|
||||||
|
c = c.substring(1);
|
||||||
|
let rgb = parseInt(c, 16);
|
||||||
|
let r = (rgb >> 16) & 0xff;
|
||||||
|
let g = (rgb >> 8) & 0xff;
|
||||||
|
let b = (rgb >> 0) & 0xff;
|
||||||
|
|
||||||
|
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<nav class="navbar navbar-expand-lg">
|
<nav class="navbar navbar-expand-lg">
|
||||||
<a class="navbar-brand" href="/">sist2</a>
|
<a class="navbar-brand" href="/">sist2</a>
|
||||||
|
<span class="badge badge-pill version">v1.1.8</span>
|
||||||
<span class="tagline">Lightning-fast file system indexer and search tool </span>
|
<span class="tagline">Lightning-fast file system indexer and search tool </span>
|
||||||
<a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a>
|
<a style="margin-left: auto" id="theme" class="btn" title="Toggle theme" href="/">Theme</a>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -24,9 +25,9 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<div class="input-group-text">
|
<div class="input-group-text">
|
||||||
<span onclick="document.getElementById('barToggle').click()">Must match </span>
|
<span title="Toggle fuzzy searching" onclick="document.getElementById('fuzzyToggle').click()">Fuzzy </span>
|
||||||
<input title="Toggle between 'Should' and 'Must' match mode" type="checkbox" id="barToggle"
|
<input title="Toggle fuzzy searching" type="checkbox" id="fuzzyToggle"
|
||||||
onclick="toggleSearchBar()" checked>
|
onclick="toggleFuzzy()" checked>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input id="searchBar" type="search" class="form-control" placeholder="Search">
|
<input id="searchBar" type="search" class="form-control" placeholder="Search">
|
||||||
@@ -41,11 +42,25 @@
|
|||||||
<select class="custom-select" id="indices" multiple size="6"></select>
|
<select class="custom-select" id="indices" multiple size="6"></select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col">
|
<div class="col" id="treeTabs">
|
||||||
<label>Mime types</label>
|
<ul class="nav nav-tabs" role="tablist">
|
||||||
|
<li class="nav-item">
|
||||||
<div class="tree"></div>
|
<a class="nav-link active" data-toggle="tab" href="#mime" role="tab" aria-controls="home" aria-selected="true">Mime Types</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" data-toggle="tab" href="#tag" role="tab" aria-controls="profile" aria-selected="false" title="User-defined tags">Tags</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content" id="myTabContent">
|
||||||
|
<div class="tab-pane fade show active" id="mime" role="tabpanel" aria-labelledby="home-tab">
|
||||||
|
<div id="mimeTree" class="tree"></div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade" id="tag" role="tabpanel" aria-labelledby="profile-tab">
|
||||||
|
<div id="tagTree" class="tree"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user