• 私有云盘Nextcloud在线解压开发(瞎搞瞎搞0.0)


    私有云盘 Nextcloud在线解压开发

    缘由:
    问:为啥百度网盘会员人家可以在线解压哇???
    我:what?那必须安排哇!!!

    1. python代码如下
    from flask import Flask, request, jsonify, abort
    from flask_cors import CORS
    import sys
    import os
    import zipfile
    import hashlib
    import subprocess
    sys.path.append(os.path.dirname(os.path.dirname(__file__)))
    app = Flask(__name__)
    #跨域,允许所有
    CORS(app)
    
    def Shell_cmd():
            xhel = "chown -R 33.tape /home/nextcloud/data/admin/files"    #nextcloud文件目录赋权限
            Cmd_run = subprocess.run(xhel,shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode("utf-8")
            return Cmd_run
    
    
    def extract_zip_filename(file_path):
        file_name = os.path.basename(file_path)  # 获取文件名,包含扩展名
        if file_name.endswith('.zip'):
            zip_name = file_name[:-4]  # 去掉末尾的'.zip'扩展名
            return zip_name
        else:
            return None  # 如果文件不是.zip文件,返回None或者适当的错误信息
    
    
    def unzip_file(file_path, extract_path):
        try:
          with zipfile.ZipFile(file_path, 'r') as zip_ref:
            for member in zip_ref.infolist():
                member.filename = member.filename.encode('cp437').decode('gbk')
                zip_ref.extract(member, extract_path)
        except:
            print("111")
    
    def main(zip_file_path):
       try:
        folder_name = os.path.splitext(os.path.basename(zip_file_path))[0]
        extract_path = os.path.join(os.path.dirname(zip_file_path), folder_name)
    
        unzip_file(zip_file_path, extract_path)
       except:
           print(222)
    
    
    def find_zip_files(directory):
        result = {}  # 存储结果的字典
    
        for root, dirs, files in os.walk(directory):
            for folder in dirs:  # 遍历所有文件夹
                folder_path = os.path.join(root, folder)
                zip_files = []  # 存储该文件夹内的zip文件路径
                for file in os.listdir(folder_path):  # 遍历文件夹内的文件
                    file_path = os.path.join(folder_path, file)
                    if file.endswith('.zip'):  # 判断是否为zip文件
                        zip_files.append(file_path)
                if zip_files:  # 如果文件夹内有zip文件,则将其添加到结果字典中
                    result[folder] = zip_files
        return result
    
    
    
    @app.route('/unzip', methods=['POST'])
    def unzip():
        # 获取 POST 请求的 json 数据
        data = request.get_json()
        mulu_name = data.get('mulu')
        path_name = data.get('path')
        Authentication  = data.get('authentication')
        print(data)
        if mulu_name is not None and path_name is not None:
            if Authentication == "7a1b805e3ffd55luozi":
                 zip_file_path = f"{path_name}"
                 main(zip_file_path)
                 file_path = extract_zip_filename(zip_file_path)
                 Shell_cmd()
                 return jsonify(file_path)
    
    @app.route('/update', methods=['POST'])
    def update():
        # 获取 POST 请求的 json 数据
        data = request.get_json()
        Authentication  = data.get('authentication')
        if Authentication == "705e3ffd55luozi":
            directory = '/home/nextcloud/data/admin/files/'  # 替换为你的目标路径
            result_dict = find_zip_files(directory)
            return jsonify(result_dict)
    
    
    if __name__ == '__main__':
        app.run(debug=True,host='0.0.0.0',port=6080)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    1. html 代码
    DOCTYPE html>
    <html>
    
    <head>
      <meta charset="UTF-8">
      <title>Nextcloud 解压title>
      <style>
        * {
          margin: 0;
          padding: 0;
          box-sizing: border-box;
        }
    
        body {
          font-family: Arial, sans-serif;
          background-color: #f4f4f4;
        }
    
        h1 {
          text-align: center;
          margin-top: 50px;
          font-size: 36px;
          font-weight: bold;
        }
    
        form {
          width: 80%;
          max-width: 600px;
          margin: 50px auto;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          background-color: #fff;
          /* background-color: #f4f4f4; */
          border-radius: 10px;
          padding: 30px;
          box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
    
        label {
          font-size: 18px;
          font-weight: bold;
          margin-bottom: 10px;
        }
    
        select {
          width: 100%;
          height: 40px;
          border-radius: 5px;
          background-color: #f4f4f4;
          border: none;
          outline: none;
          font-size: 16px;
          margin-bottom: 20px;
        }
    
        button {
          width: 180px;
          height: 50px;
          font-size: 18px;
          font-weight: bold;
          background-color: #007aff;
          color: #fff;
          border: none;
          border-radius: 5px;
          cursor: pointer;
          transition: all 0.2s ease-in-out;
          box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.1), 0px 4px 10px rgba(0, 0, 0, 0.05);
        }
    
        button:hover {
          background-color: #0065cc;
        }
    
    
        .combobox-container {
      position: relative;
      width: 100%;
          height: 40px;
          border-radius: 5px;
          background-color: #f4f4f4;
          border: none;
          outline: none;
          font-size: 16px;
          margin-bottom: 20px;
    }
    
    .combobox-input {
    
      width: 100%;
      height: 40px;
      border-radius: 5px;
      padding: 0.375rem 0.75rem;
      background-color: #f4f4f4;
      font-size: 1rem;
      border: 1px solid #f4f4f4;
      border-radius: 0.25rem;
      -webkit-appearance: none;
         -moz-appearance: none;
              appearance: none;
    }
    
    .combobox-options {
      display: none;
      position: absolute;
      top: calc(100% + 1px);
      left: 0;
      z-index: 9999;
      width: 100%;
      max-height: 200px;
      overflow: auto;
      background-color: #f4f4f4;
      border: 1px solid #f4f4f4;
      border-top: none;
      border-bottom-right-radius: 0.25rem;
      border-bottom-left-radius: 0.25rem;
    }
    
    .combobox-options div {
      padding: 0.375rem 0.75rem;
      cursor: pointer;
    }
    
    .combobox-options div:hover {
      background-color: #f4f4f4;
    }
    /* 历史日志 */
    #text-box {
        position: fixed;
        top: 10%;
        height: 50%;
        right: 0.5%;
        padding: 10px;
        background-color: #f4f4f4;
        box-shadow: 0 0 5px  #231f47;
    }
    
    /* #text-box textarea {
        width: 100%;
        height: 100%;
        background-color: #f4f4f4;
        border: none;
        resize: none;
    } */
      style>
      <script src="cdn.bootcdn.net_ajax_libs_jquery_3.6.0_jquery.min.js">script>
    head>
    
    <body>
      <h1>Nextcloud 解压h1>
    
      
      
    
      <form>
        <label for="project">文件夹:label>
        <select id="parentSelect" class="combobox-container" onchange="updateChildOptions()">
          <option value="">文件夹option>
        select>
    
    
    
        <label for="environment">ZIP包名:label>
        <select id="childSelect" class="combobox-container">
          <option value="">ZIP包名:option>
        select>
    
        <div style="width:100%; display:flex; justify-content: center;">
          
          <button type="button" onclick="deploy()">确认button>
            div>
    
      <p  rows="10" cols="50" readonly  style="margin-left:30px;width: 400px; height: 95%; " >
      解压完毕,需要在你的zip包路径下,创建一个相同的文件夹名字(及完成之后提示的名字)
      p>
    
      form>
    
    
      <script>
                 // 更新父框选项
          function updateParentOptions(data) {
            var parentSelect = document.getElementById('parentSelect');
    
            for (var key in data) {
              if (data.hasOwnProperty(key)) {
                var option = document.createElement('option');
                option.value = key;
                option.text = key;
                parentSelect.appendChild(option);
              }
            }
          }
    
          // 更新子框选项
          function updateChildOptions() {
            var parentSelect = document.getElementById('parentSelect');
            var childSelect = document.getElementById('childSelect');
    
            var selectedParent = parentSelect.value;
            childSelect.innerHTML = ''; // 清空子框选项
    
            if (selectedParent && data.hasOwnProperty(selectedParent)) {
              var childOptions = data[selectedParent];
    
              for (var i = 0; i < childOptions.length; i++) {
                var option = document.createElement('option');
                option.value = childOptions[i];
                option.text = childOptions[i];
                childSelect.appendChild(option);
              }
            }
          }
    
    
        // 发布
        function deploy() {
          alert('处理中......');
          var project = $('#parentSelect').val();
          var environment = $('#childSelect').val();
          if (project == '') {
            alert('请选择要目录');
            return;
          }
          if (environment == '') {
            alert('请选择zip包名');
            return;
          }
          const  data = {
              mulu: project,
              path: environment,
              authentication: "7a87edec6bfbba4a1b805e3ffd55luozi"
            };
          $.ajax({
            type: 'POST',
            url: 'https://www.test.com:66/pi/unzip',
            contentType: 'application/json',
            data: JSON.stringify(data),
            xhrFields: {
              withCredentials: true
              },
            rejectUnauthorized: false,
            success: function(data_res) {
              var data = data_res
              console.log(data)
              alert('解压成功请创建目录:' + data);
            },
            error: function(xhr, status, error) {
              if (xhr.status === 403) {
                alert('参数错误');
              } else if (xhr.status === 401) {
                alert('镜像同步失败');
              } else {
              alert('解压失败');
            }
          }
          });
        }
    
             // 发送Ajax请求
             function update() {
            // alert('处理中......');
            const data2 = {
              authentication: "7a87edec6bfbba4a1b805e3ffd55luozi"
            };
    
            $.ajax({
              type: 'POST',
              url: 'https://www.test.com:66/update',
              contentType: 'application/json',
              data: JSON.stringify(data2),
              xhrFields: {
                withCredentials: true
                },
              rejectUnauthorized: false,
              success: function(responseData) {
                // alert('更新成功');dd
                var data = responseData;  // 将返回的JSON字符串解析为JavaScript对象
                // 使用responseData进行进一步操作,例如读取其中的键值对
                updateParentOptions(data);
                window.data = data;
                console.log(data.key1);
                console.log(data.key2);
              },
              error: function(xhr, status, error) {
                if (xhr.status === 403) {
                  alert('参数错误');
                } else if (xhr.status === 400) {
                  alert('写文件失败');
                } else {
                  alert('更新失败');
                }
              }
            });
          }
    
          update(); // 发送ajax请求
    
      script>
    body>
    
    html>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    1. nignx配置
    ...
          location  /api/ {
          proxy_buffering off;
          proxy_set_header Host $http_host;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Referer "https://192.168.2.200";
          proxy_pass http://192.168.2.200:6080/;
    }
    
    ...
      location  /unzip/ {
      index  index.html index.htm;
        alias   /data/unzip/;
    }
    ...
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    1. 效果展示
      在这里插入图片描述
      在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    CDB PDB 在mount 下 service状态
    【蒸汽冷凝器型号和PI控制】具有PID控制的蒸汽冷凝器的动力学模型(Matlab&Simulink)
    day065:IO流、字节流、字节流写数据
    SQL Server数据库语法篇(终篇)
    ubuntu18.04安装显卡驱动,cuda,cudnn
    存在重复元素(简单)
    【NLP】第 5 章:循环神经网络和情感分析
    某大型房地产公司绩效面谈项目成功案例纪实
    SSM框架,SpringMVC框架的学习(上)
    GoAccess请求监控
  • 原文地址:https://blog.csdn.net/weixin_43606975/article/details/132625006