2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import requests
|
2024-01-12 12:34:01 +08:00
|
|
|
from flask_restful import Resource, reqparse
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-07-21 01:11:40 +08:00
|
|
|
from configs import dify_config
|
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
from . import api
|
|
|
|
|
|
|
|
|
|
|
|
class VersionApi(Resource):
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
parser = reqparse.RequestParser()
|
|
|
|
parser.add_argument('current_version', type=str, required=True, location='args')
|
|
|
|
args = parser.parse_args()
|
2024-07-21 01:11:40 +08:00
|
|
|
check_update_url = dify_config.CHECK_UPDATE_URL
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2024-06-05 00:13:04 +08:00
|
|
|
result = {
|
2024-07-21 01:11:40 +08:00
|
|
|
'version': dify_config.CURRENT_VERSION,
|
2024-06-05 00:13:04 +08:00
|
|
|
'release_date': '',
|
|
|
|
'release_notes': '',
|
|
|
|
'can_auto_update': False,
|
|
|
|
'features': {
|
2024-07-21 01:11:40 +08:00
|
|
|
'can_replace_logo': dify_config.CAN_REPLACE_LOGO,
|
|
|
|
'model_load_balancing_enabled': dify_config.MODEL_LB_ENABLED
|
2023-05-23 17:34:48 +08:00
|
|
|
}
|
2024-06-05 00:13:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if not check_update_url:
|
|
|
|
return result
|
2023-05-23 17:34:48 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
try:
|
|
|
|
response = requests.get(check_update_url, {
|
|
|
|
'current_version': args.get('current_version')
|
|
|
|
})
|
|
|
|
except Exception as error:
|
2023-06-25 16:49:14 +08:00
|
|
|
logging.warning("Check update version error: {}.".format(str(error)))
|
2024-06-05 00:13:04 +08:00
|
|
|
result['version'] = args.get('current_version')
|
|
|
|
return result
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
content = json.loads(response.content)
|
2024-06-05 00:13:04 +08:00
|
|
|
result['version'] = content['version']
|
|
|
|
result['release_date'] = content['releaseDate']
|
|
|
|
result['release_notes'] = content['releaseNotes']
|
|
|
|
result['can_auto_update'] = content['canAutoUpdate']
|
|
|
|
return result
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
api.add_resource(VersionApi, '/version')
|