Browse Source

update subweb

Stille 3 years ago
parent
commit
5326269875

+ 0 - 2
subweb/.env

@@ -1,2 +0,0 @@
-NODE_ENV = 'development'
-VUE_APP_BASE_API_URL = 'http://127.0.0.1:25500'

+ 0 - 2
subweb/.env.production

@@ -1,2 +0,0 @@
-NODE_ENV = 'production'
-VUE_APP_BASE_API_URL = 'http://127.0.0.1:25500'

+ 2 - 1
subweb/Dockerfile

@@ -8,5 +8,6 @@ RUN npm run build
 
 FROM nginx:1.16-alpine
 COPY --from=build /app/dist /usr/share/nginx/html
+COPY . /app
 EXPOSE 80
-CMD [ "nginx", "-g", "daemon off;" ]
+CMD [ "sh", "-c", "/app/start.sh" ]

+ 25 - 16
subweb/README.md

@@ -1,8 +1,4 @@
 # subweb
-GitHub [stilleshan/dockerfiles](https://github.com/stilleshan/dockerfiles)  
-Docker [stilleshan/subweb](https://hub.docker.com/r/stilleshan/subweb)
-> *docker image support for X86 and ARM*
-
 ## 简介
 subweb 是基于 subconverter 订阅转换的前端项目,方便用户快速生成各平台的订阅链接.
 
@@ -10,6 +6,7 @@ subweb 是基于 subconverter 订阅转换的前端项目,方便用户快速生
 
 *GitHub [stilleshan/subweb](https://github.com/stilleshan/subweb)  
 Docker [stilleshan/subweb](https://hub.docker.com/r/stilleshan/subweb)*
+> *docker image support for X86 and ARM*
 
 ## 示例
 [https://sub.ops.ci](https://sub.ops.ci)  
@@ -17,27 +14,39 @@ Docker [stilleshan/subweb](https://hub.docker.com/r/stilleshan/subweb)*
 
 ## 部署
 ### docker 本地版
-*适用于本机部署使用*
+*适用于本机快速部署使用*
 ```shell
-docker run -d --name subweb --restart always -p 18080:80 stilleshan/subweb
+docker run -d --name subweb --restart always \
+  -p 18080:80 \
+  stilleshan/subweb
 ```
 
 访问 `http://127.0.0.1:18080`
 
-### docker 在线版 (自定义后端 API)
-*适用于服务器部署,配合域名反代使用*
+### docker 自定义版
+自定义版可以挂载配置文件来修改`API 地址`,`站点名称`,`导航链接`.  
+参考以下命令,修改本地挂载路径,启动容器后会生成`config.js`配置文件,更改后刷新生效.
+
+```shell
+docker run -d --name subweb --restart always \
+  -p 18080:80 \
+  -v /PATH/subweb/conf:/usr/share/nginx/html/conf \
+  stilleshan/subweb
+```
 
-**修改自定义 subconverter API 地址需要自行编译构建镜像. ** 
+同时也可以不挂载目录,直接通过`-e`环境变量来修改`API 地址`和`站点名称`,但是无法修改`导航链接`.
 ```shell
-git clone https://github.com/stilleshan/subweb
-cd subweb
-# 修改 .env.productionn 中 VUE_APP_BASE_API_URL 为你 subconverter 后端 API 地址.
-docker build -t subweb .
-# 构建镜像
-docker run -d --name subweb --restart always -p 18080:80 subweb
-# 启动容器
+docker run -d --name subweb --restart always \
+  -p 18080:80 \
+  -e SITE_NAME=subweb \
+  -e API_URL=https://sub.ops.ci \
+  stilleshan/subweb
 ```
 
+访问 `http://127.0.0.1:18080`  
+> *推荐使用 nginx 反向代理部署*
+
+
 ## 链接
 - [GitHub - stilleshan/subweb](https://github.com/stilleshan/subweb)
 - [GitHub - stilleshan/subconverter](https://github.com/stilleshan/subconverter)

+ 16 - 0
subweb/public/conf/config.js

@@ -0,0 +1,16 @@
+window.config = {
+  siteName: 'Subconverter Web',
+  apiUrl: 'http://127.0.0.1:25500',
+  menuItem: [
+    {
+      title: '首页',
+      link: '/',
+      target: '',
+    },
+    {
+      title: 'GitHub',
+      link: 'https://github.com/stilleshan/subweb',
+      target: '_blank',
+    },
+  ],
+};

+ 1 - 0
subweb/public/index.html

@@ -6,6 +6,7 @@
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
     <link rel="icon" href="<%= BASE_URL %>favicon.ico">
     <title><%= htmlWebpackPlugin.options.title %></title>
+    <script type="text/javascript" src="<%= BASE_URL %>conf/config.js"></script>
   </head>
   <body>
     <noscript>

+ 9 - 7
subweb/src/layouts/components/header/NavBar.vue

@@ -1,12 +1,12 @@
 <template>
   <header id="header" class="reveal">
-    <h1><a href="/">Subconverter Web</a></h1>
+    <h1>
+      <a href="/">{{ siteName }}</a>
+    </h1>
     <nav id="nav" ref="navBar">
       <ul>
-        <li v-for="i in navBarItem" :key="i" :class="i.style">
-          <a :href="i.link" :class="i.class" :target="i.target">{{
-            i.title
-          }}</a>
+        <li v-for="i in navBarItem" :key="i">
+          <a :href="i.link" :target="i.target">{{ i.title }}</a>
         </li>
       </ul>
     </nav>
@@ -14,16 +14,18 @@
 </template>
 
 <script>
-import { navBarItem } from './navBarItem';
+// import { navBarItem } from './navBarItem';
 export default {
   name: 'NavBar',
   data() {
     return {
       navBarItem: [],
+      siteName: '',
     };
   },
   created() {
-    this.navBarItem = navBarItem;
+    this.navBarItem = window.config.menuItem;
+    this.siteName = window.config.siteName;
   },
 };
 </script>

+ 4 - 4
subweb/src/layouts/components/header/NavBarMobile.vue

@@ -8,9 +8,9 @@
           :key="i"
           :href="i.link"
           :target="i.target"
-          :class="i.depth"
+          class="link depth-0"
           style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0)"
-          ><span :class="i.indent"></span>{{ i.title }}</a
+          ><span class="indent-0"></span>{{ i.title }}</a
         >
       </nav>
     </div>
@@ -18,7 +18,7 @@
 </template>
 
 <script>
-import { navBarItem } from './navBarItem';
+// import { navBarItem } from './navBarItem';
 export default {
   name: 'NavBarMobile',
   data() {
@@ -27,7 +27,7 @@ export default {
     };
   },
   created() {
-    this.navBarItem = navBarItem;
+    this.navBarItem = window.config.menuItem;
     document.addEventListener('click', (e) => {
       if (this.$refs.showPanel) {
         let isSelf = this.$refs.showPanel.contains(e.target);

+ 25 - 60
subweb/src/views/home/HomeForm.vue

@@ -2,29 +2,14 @@
   <div class="box">
     <form method="post" action="#">
       <div class="row gtr-uniform gtr-50">
-        <span v-for="(item, index) in inputs" :key="item" class="col-12 row">
-          <div
-            class="col-10 col-10-mobilep"
-            style="text-align: center; padding-top: 10px"
-          >
-            <input
-              type="text"
-              v-model.trim="item.inputValue"
-              :placeholder="item.placeholder"
-            />
-          </div>
-          <div
-            class="col-2 col-2-mobilep"
-            style="text-align: center; padding-top: 10px"
-          >
-            <input
-              type="button"
-              :value="item.buttonValue"
-              :class="item.buttonClass"
-              @click="addLinks(index)"
-            />
-          </div>
-        </span>
+        <div class="col-12">
+          <textarea
+            id="message"
+            v-model.trim="inputs.inputValue"
+            :placeholder="inputs.placeholder"
+            rows="3"
+          ></textarea>
+        </div>
         <div
           class="col-4 col-4-mobilep list"
           style="text-align: center; padding-top: 20px"
@@ -108,7 +93,7 @@
         >
           <ul class="actions">
             <li>
-              <input type="button" value="生成链接" @click="checkAll()" />
+              <input type="button" value="订阅转换" @click="checkAll()" />
             </li>
             <!-- <li><input type="reset" value="重置内容" class="alt" /></li> -->
             <li>
@@ -125,9 +110,7 @@
           <input
             type="text"
             readOnly="true"
-            :placeholder="
-              this.apiUrl + '/sub?target=' + this.targetType + '&url='
-            "
+            placeholder="点击订阅转换获取链接"
             v-model.trim="returnUrl"
           />
         </div>
@@ -172,22 +155,20 @@ export default {
       isShowMoreConfig: false,
       urls: [],
       returnUrl: '',
-      apiUrl: process.env.VUE_APP_BASE_API_URL,
+      apiUrl: window.config.apiUrl,
       manualApiUrl: '',
       isManualApi: true,
       api: 'default',
       apis: [
-        { value: 'default', text: process.env.VUE_APP_BASE_API_URL },
+        { value: 'default', text: window.config.apiUrl },
         { value: 'manual', text: '自定义后端 API 地址' },
       ],
-      inputs: [
-        {
-          buttonClass: '',
-          buttonValue: '添加',
-          inputValue: '',
-          placeholder: '订阅地址',
-        },
-      ],
+      inputs: {
+        buttonClass: '',
+        inputValue: '',
+        placeholder:
+          '多订阅链接或节点请确保每行一条\n支持手动使用"|"分割多链接或节点',
+      },
       targetType: 'clash',
       targetTypes: [
         { value: 'clash', text: 'Clash' },
@@ -223,17 +204,6 @@ export default {
     resetDialog() {
       this.dialogVisible = false;
     },
-    addLinks(index) {
-      if (index == 0) {
-        this.inputs.push({
-          buttonClass: 'alt',
-          buttonValue: '移除',
-          placeholder: '订阅地址',
-        });
-      } else {
-        this.inputs.splice(index, 1);
-      }
-    },
     selectApi(event) {
       if (event.target.value == 'manual') {
         this.isManualApi = false;
@@ -245,18 +215,13 @@ export default {
       this.targetType = event.target.value;
     },
     checkUrls() {
-      this.urls = [];
-      for (const i in this.inputs) {
-        if (utils.regexCheck(this.inputs[i].inputValue)) {
-          this.urls.push(this.inputs[i].inputValue);
-          if (Number(i) + 1 == this.inputs.length) {
-            return true;
-          }
-        } else {
-          this.dialogMessage = '请填写正确的订阅地址';
-          this.dialogVisible = true;
-          return false;
-        }
+      if (this.inputs.inputValue == '') {
+        this.dialogMessage = '请填写正确的订阅地址';
+        this.dialogVisible = true;
+        return false;
+      } else {
+        this.urls = this.inputs.inputValue;
+        return true;
       }
     },
     checkApi() {

+ 2 - 1
subweb/src/views/home/utils.js

@@ -5,7 +5,8 @@ const getSubLink = function (
   isShowMoreConfig,
   moreConfig
 ) {
-  let link = links.join('|');
+  let linkLst = links.split('\n');
+  let link = linkLst.join('|');
   let finalUrl =
     apiUrl + '/sub?target=' + targetType + '&url=' + encodeURIComponent(link);
   if (isShowMoreConfig) {

+ 18 - 0
subweb/start.sh

@@ -0,0 +1,18 @@
+#/bin/sh
+if [ ! -f /usr/share/nginx/html/conf/config.js ]; then
+  cp /app/public/conf/config.js /usr/share/nginx/html/conf
+fi
+
+if [ $API_URL ]; then
+  echo "当前 API 地址为: $API_URL"
+  sed -i "s#http://127.0.0.1:25500#$API_URL#g" /usr/share/nginx/html/conf/config.js
+else
+  echo "当前为默认本地 API 地址: http://127.0.0.1:25500"
+  echo "如需修改请在容器启动时使用 -e API_URL='https://sub.ops.ci' 传递环境变量"
+fi
+
+if [ $SITE_NAME ]; then
+  sed -i "s#Subconverter Web#$SITE_NAME#g" /usr/share/nginx/html/conf/config.js
+fi
+
+nginx -g "daemon off;"