Lsky Pro挂载alist

首先需要去修改lsky代码,如果是docker可以

docker exec -it lsky-pro /bin/bash

然后安装个vim

apt install vim
cd app
cd Services/
ls
vi ImageService.php

然后vim输入

:set nu

显示行号,然后找到345行,粘贴进去

'authType' => 1,

lwebdav存储策略问题 · Issue #497 · lsky-org/lsky-pro

图床配置

访问域名是生成的图片直链地址

上传效果

获得token

使用类似的py代码即可

import requests

def get_token(email, password):
    url = 'http://xxxxx/api/v1/tokens'  # 请替换为实际的API地址
    payload = {
        'email': email,
        'password': password
    }
    
    response = requests.post(url, json=payload)
    
    if response.status_code == 200:
        data = response.json()
        if data['status']:
            return data['data']['token']
        else:
            print(f"获取Token失败: {data['message']}")
            return None
    else:
        print(f"请求错误,状态码: {response.status_code}")
        return None

# 使用示例
email = 'email'  # 替换为你的邮箱
password = 'pwd'  # 替换为你的密码
token = get_token(email, password)
if token:
    print(f"获取到的Token是: {token}")

使用token发送图片

import requests

def upload_image(token, file_path, strategy_id=None):
    url = 'https://xxxx/api/v1/upload'
    headers = {
        'Authorization': f'Bearer {token}',
        'Accept': 'application/json',
        #'Content-Type': 'multipart/form-data'
    }
    
    files = {
        'file': open(file_path, 'rb')
    }
    
    if strategy_id is not None:
        files['strategy_id'] = strategy_id
    
    response = requests.post(url, headers=headers, files=files)

    if response.status_code == 200:
        data = response.json()
        if data['status']:
            print(f"图片上传成功: {data['message']}")
            print(f"图片链接: {data['data']['links']['url']}")
        else:
            print(f"图片上传失败: {data['message']}")
    else:
        print(f"请求错误,状态码: {response.status_code}")

# 使用示例
token = '1|aaa'  # 替换为你的Token
file_path = 'D:\\test.png'  # 替换为你的图片文件路径
strategy_id = None  # 如果有储存策略ID,则替换为对应的ID

upload_image(token, file_path, strategy_id)

 

posted @ 2024-12-02 12:18  qbning  阅读(12)  评论(0编辑  收藏  举报
描述