Skip to content

Commit

Permalink
格式修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Gandum2077 committed Feb 16, 2020
1 parent 50444d5 commit 81c534c
Show file tree
Hide file tree
Showing 22 changed files with 539 additions and 501 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
assets/userConfig.json
assets/favorites.db
assets/.files
.output
14 changes: 14 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": false,
"trailingComma": "none",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid",
"requirePragma": false,
"insertPragma": false,
"proseWrap": "preserve"
}
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# JSBox Booru
JSBox平台的Booru客户端。在JSBox上连接Gelbooru或Danbooru类型的站点,并欣赏数以万计的动漫相关图片!
# JSBooru

JSBox 平台的 Booru 客户端。在 JSBox 上连接 Gelbooru 或 Danbooru 类型的站点,并欣赏数以万计的动漫相关图片!
现已支持十余个不同的站点。

## Features

- 标签搜索
- 幻灯片播放
- 检索、收藏、管理标签
- 收藏图片
- 下载不同尺寸的图片
- 支持安全搜索模式,过滤NSFW图片
- 支持17个网站
- 支持安全搜索模式,过滤 NSFW 图片
- 支持 17 个网站

## Requirements
1. JSBox>=2.2.0,需要Node.js功能,iOS>=13.0.0

1. JSBox>=2.2.0,需要 Node.js 功能,iOS>=13.0.0
2. 良好的网络环境,此部分请参见 [Known issues](#known-issues)
3. node modules `booru`,点击左上角按钮并选择“解决模块依赖”来安装

## Known issues

1. 网络错误

- 墙国居民请先确定自己的设备已经科学上网
- Node.js使用了SSL Pinning(证书锁定)技术,因此不能使用MITM工具
- 一部分代理App的自动分流功能不能正确分类Node.js的访问请求,请自行修正规则,或者直接改为全局代理模式
- 墙国居民请先确定自己的设备已经科学上网
- Node.js 使用了 SSL Pinning(证书锁定)技术,因此不能使用 MITM 工具
- 一部分代理 App 的自动分流功能不能正确分类 Node.js 的访问请求,请自行修正规则,或者直接改为全局代理模式

2. Node.js运行时偶尔会有不工作的情况,如果遇到请重启JSBox
3. 部分站点工作不正常。修复此问题需要首先解决上游依赖项目的bug,不过你可以先反馈问题
2. Node.js 运行时偶尔会有不工作的情况,如果遇到请重启 JSBox
3. 部分站点工作不正常。修复此问题需要首先解决上游依赖项目的 bug,不过你可以先反馈问题
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"info": {
"name": "JSBoxBooru",
"name": "JSBooru",
"url": "",
"version": "0.5.0",
"author": "Gandum2077",
"website": "https://github.com/Gandum2077",
"website": "https://github.com/Gandum2077/JSBooru",
"types": 1
},
"settings": {
Expand Down
9 changes: 2 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
let socketLogger = require("socketLogger")
typeof socketLogger.init === 'function' && socketLogger.init('192.168.50.134')
// SocketLogger Auto Generation Code

const app = require("scripts/app")

app.init()
const app = require("scripts/app");
app.init();
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jsbox-booru",
"name": "jsbooru",
"version": "1.0.0",
"description": "",
"main": "index.js",
Expand Down
4 changes: 2 additions & 2 deletions prefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
{
"title": "Report Bugs",
"type": "link",
"value": "https://github.com/Gandum2077/jsbox-booru/issues"
"value": "https://github.com/Gandum2077/JSBooru/issues"
}
]
}
]
}
}
24 changes: 12 additions & 12 deletions scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
const constants = require("scripts/utils/constants")
const listView = require("scripts/views/listView")
const { createDB } = require("scripts/utils/database")
const constants = require("scripts/utils/constants");
const listView = require("scripts/views/listView");
const { createDB } = require("scripts/utils/database");

function initDatabase() {
if (!$file.exists(constants.databaseFile)) {
createDB()
createDB();
}
}

function checkPrefs() {
const intervals = $prefs.get("slideshow_intervals")
const intervals = $prefs.get("slideshow_intervals");
if (intervals < 1 || intervals > 30) {
$prefs.set("slideshow_intervals", 5)
$prefs.set("slideshow_intervals", 5);
}
}

async function init() {
constants.initConfig()
initDatabase()
checkPrefs()
await listView()
$app.tips("右上角按钮 - Servers切换站点,Help查看帮助,Settings查看设置")
constants.initConfig();
initDatabase();
checkPrefs();
await listView();
$app.tips("右上角按钮 - Servers切换站点,Settings进行设置,Help查看帮助");
}

module.exports = {
init
}
};
73 changes: 32 additions & 41 deletions scripts/booru/booru.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,43 @@
const Booru = require('booru')
const { BooruError, sites } = require('booru')
const Booru = require("booru");
const { BooruError, sites } = require("booru");

const {site = 'safebooru', tags = [], limit = 50, random = false, page = 1 } = $context.query
console.log("Node.js works")
const {
site = "safebooru",
tags = [],
limit = 50,
random = false,
page = 1
} = $context.query;
console.log("Node.js works");

function sendResult({
posts = null,
error = null
}) {
function sendResult({ posts = null, error = null }) {
$jsbox.notify("booruSearch", {
posts,
error
});
}

function search({
site,
tags,
limit,
random,
page
}) {
function search({ site, tags, limit, random, page }) {
// Search with promises
Booru.search(site, tags, { limit: limit, random: random, page: page})
.then(posts => {
//Log the direct link to each image
sendResult(posts)
})
.catch(err => {
if (err instanceof BooruError) {
// It's a custom error thrown by the package
// Typically results from errors the boorus returns, eg. "too many tags"
sendResult({
error: err.message
})
} else {
// This means something pretty bad happened
sendResult({
error: err
})
}
})
Booru.search(site, tags, { limit, random, page })
.then(posts => {
//Log the direct link to each image
sendResult(posts);
})
.catch(err => {
if (err instanceof BooruError) {
// It's a custom error thrown by the package
// Typically results from errors the boorus returns, eg. "too many tags"
sendResult({
error: err.message
});
} else {
// This means something pretty bad happened
sendResult({
error: err
});
}
});
}

search({
site,
tags,
limit,
random,
page
})
search({ site, tags, limit, random, page });
4 changes: 2 additions & 2 deletions scripts/booru/filter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function safeSearchFilter(items) {
return items.filter(n => n.rating === 's')
return items.filter(n => n.rating === "s");
}

module.exports = {
safeSearchFilter
}
};
43 changes: 20 additions & 23 deletions scripts/booru/generator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { searchFavorites, getCount } = require('scripts/utils/database')
const search = require('./search')
const { searchFavorites, getCount } = require("scripts/utils/database");
const search = require("./search");

async function* generatorForSite({
site,
Expand All @@ -8,8 +8,8 @@ async function* generatorForSite({
random = false,
startPage = 1
}) {
let currentPage = startPage
let continueFlag = true
let currentPage = startPage;
let continueFlag = true;
while (continueFlag) {
try {
const result = await search({
Expand All @@ -18,34 +18,31 @@ async function* generatorForSite({
limit,
random,
page: currentPage
})
yield result
currentPage++
} catch(err) {
continueFlag = false
console.error(result)
return
});
yield result;
currentPage++;
} catch (err) {
continueFlag = false;
console.error(err);
return;
}
}
}

async function* generatorForFavorites({
site = null,
startPage = 1
}) {
let currentPage = startPage
const totalPage = Math.ceil(getCount() / 50)
async function* generatorForFavorites({ site = null, startPage = 1 }) {
let currentPage = startPage;
const totalPage = Math.ceil(getCount() / 50);
do {
const items = searchFavorites({
site,
site,
page: currentPage
})
yield items
currentPage++
} while (currentPage < totalPage)
});
yield items;
currentPage++;
} while (currentPage < totalPage);
}

module.exports = {
generatorForSite,
generatorForFavorites
}
};
26 changes: 7 additions & 19 deletions scripts/booru/search.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
function booruSearch({
site,
tags,
limit,
random,
page
}) {
function booruSearch({ site, tags, limit, random, page }) {
return new Promise((resolve, reject) => {
$nodejs.run({
path: "scripts/booru/booru.js",
query: {
site,
tags,
limit,
random,
page
},
query: { site, tags, limit, random, page },
listener: {
id: "booruSearch",
handler: result => {
if (result.posts) {
resolve(result.posts)
resolve(result.posts);
} else {
reject(result.error)
reject(result.error);
}
}
}
})
})
});
});
}

module.exports = booruSearch
module.exports = booruSearch;
12 changes: 10 additions & 2 deletions scripts/dialogs/inputAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ const {
UIAlertController
} = require("./UIAlert");

function inputAlert({ title = "", message, placeholder }) {
function inputAlert({
title = "",
message,
text = "",
placeholder,
type = 0
} = {}) {
return new Promise((resolve, reject) => {
const alertVC = new UIAlertController(
title,
message,
UIAlertControllerStyle.Alert
);
alertVC.addTextField({
placeholder: placeholder,
placeholder,
text,
type,
events: {
shouldReturn: () => {
const input = alertVC.getText(0);
Expand Down
2 changes: 1 addition & 1 deletion scripts/dialogs/loginAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const {
UIAlertController
} = require("./UIAlert");

function loginAlert({ title = "", message, placeholder1, placeholder2 }) {
function loginAlert({ title = "", message, placeholder1, placeholder2 } = {}) {
return new Promise((resolve, reject) => {
const alertVC = new UIAlertController(
title,
Expand Down
Loading

0 comments on commit 81c534c

Please sign in to comment.