v0.6.25: Add self-update feature with hot reload
This commit is contained in:
@@ -81,6 +81,11 @@
|
|||||||
|
|
||||||
## 📝 변경 이력 (Changelog)
|
## 📝 변경 이력 (Changelog)
|
||||||
|
|
||||||
|
### v0.6.25 (2026-01-09)
|
||||||
|
- **자가 업데이트 기능 추가**: 모든 설정 페이지 (Ohli24, Anilife, Linkkf)에서 "업데이트" 버튼 클릭으로 Git Pull 및 플러그인 핫 리로드 지원
|
||||||
|
- **버전 체크 API**: GitHub에서 최신 버전 정보를 가져와 업데이트 알림 표시 (1시간 캐싱)
|
||||||
|
- **공통 베이스 통합**: `AnimeModuleBase`에 `get_update_info`, `reload_plugin` 메서드 추가로 모든 모듈에서 자동 사용 가능
|
||||||
|
|
||||||
### v0.6.24 (2026-01-08)
|
### v0.6.24 (2026-01-08)
|
||||||
- **Ohli24 GDM 연동 버그 수정**:
|
- **Ohli24 GDM 연동 버그 수정**:
|
||||||
- **썸네일 누락 해결**: GDM 위임 시 `image` 키를 `thumbnail`로 올바르게 매핑하여 목록에서 이미지가 보이도록 수정.
|
- **썸네일 누락 해결**: GDM 위임 시 `image` 키를 `thumbnail`로 올바르게 매핑하여 목록에서 이미지가 보이도록 수정.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
title: "애니 다운로더"
|
title: "애니 다운로더"
|
||||||
version: 0.6.23
|
version: 0.6.25
|
||||||
package_name: "anime_downloader"
|
package_name: "anime_downloader"
|
||||||
developer: "projectdx"
|
developer: "projectdx"
|
||||||
description: "anime downloader"
|
description: "anime downloader"
|
||||||
|
|||||||
124
mod_base.py
124
mod_base.py
@@ -5,6 +5,10 @@ import os, traceback, time, json
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
class AnimeModuleBase(PluginModuleBase):
|
class AnimeModuleBase(PluginModuleBase):
|
||||||
|
# 업데이트 체크 캐싱 (클래스 레벨)
|
||||||
|
_last_update_check = 0
|
||||||
|
_latest_version = None
|
||||||
|
|
||||||
def __init__(self, P, setup_default=None, **kwargs):
|
def __init__(self, P, setup_default=None, **kwargs):
|
||||||
super(AnimeModuleBase, self).__init__(P, **kwargs)
|
super(AnimeModuleBase, self).__init__(P, **kwargs)
|
||||||
self.P = P # Ensure P is available via self.P
|
self.P = P # Ensure P is available via self.P
|
||||||
@@ -131,6 +135,37 @@ class AnimeModuleBase(PluginModuleBase):
|
|||||||
arg3 = request.form.get('arg3') or request.args.get('arg3')
|
arg3 = request.form.get('arg3') or request.args.get('arg3')
|
||||||
return self.process_command(command, arg1, arg2, arg3, req)
|
return self.process_command(command, arg1, arg2, arg3, req)
|
||||||
|
|
||||||
|
elif sub == 'self_update':
|
||||||
|
# 자가 업데이트 (Git Pull) 및 모듈 리로드
|
||||||
|
try:
|
||||||
|
import subprocess
|
||||||
|
plugin_path = os.path.dirname(os.path.dirname(__file__)) if '__file__' in dir() else os.path.dirname(__file__)
|
||||||
|
# 실제 플러그인 루트 디렉토리
|
||||||
|
plugin_path = os.path.dirname(__file__)
|
||||||
|
self.P.logger.info(f"애니 다운로더 자가 업데이트 시작: {plugin_path}")
|
||||||
|
|
||||||
|
cmd = ['git', '-C', plugin_path, 'pull']
|
||||||
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||||
|
stdout, stderr = process.communicate()
|
||||||
|
|
||||||
|
if process.returncode != 0:
|
||||||
|
raise Exception(f"Git pull 실패: {stderr}")
|
||||||
|
|
||||||
|
self.P.logger.info(f"Git pull 결과: {stdout}")
|
||||||
|
|
||||||
|
# 모듈 리로드
|
||||||
|
self.reload_plugin()
|
||||||
|
|
||||||
|
return jsonify({'ret': 'success', 'msg': f"업데이트 및 리로드 완료!<br><pre>{stdout}</pre>", 'data': stdout})
|
||||||
|
except Exception as e:
|
||||||
|
self.P.logger.error(f"자가 업데이트 중 오류: {str(e)}")
|
||||||
|
self.P.logger.error(traceback.format_exc())
|
||||||
|
return jsonify({'ret': 'danger', 'msg': f"업데이트 실패: {str(e)}"})
|
||||||
|
|
||||||
|
elif sub == 'check_update':
|
||||||
|
force = req.form.get('force') == 'true'
|
||||||
|
return jsonify({'ret': 'success', 'data': self.get_update_info(force=force)})
|
||||||
|
|
||||||
return jsonify({'ret': 'fail', 'log': f"Unknown sub: {sub}"})
|
return jsonify({'ret': 'fail', 'log': f"Unknown sub: {sub}"})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -198,3 +233,92 @@ class AnimeModuleBase(PluginModuleBase):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {'ret': 'fail', 'msg': str(e)}
|
return {'ret': 'fail', 'msg': str(e)}
|
||||||
|
|
||||||
|
def get_update_info(self, force=False):
|
||||||
|
"""GitHub에서 최신 버전 정보 가져오기 (캐싱 활용)"""
|
||||||
|
import requests
|
||||||
|
now = time.time()
|
||||||
|
|
||||||
|
# 실제 로컬 파일에서 현재 버전 읽기
|
||||||
|
current_version = self.P.plugin_info.get('version', '0.0.0')
|
||||||
|
try:
|
||||||
|
info_path = os.path.join(os.path.dirname(__file__), 'info.yaml')
|
||||||
|
if os.path.exists(info_path):
|
||||||
|
import yaml
|
||||||
|
with open(info_path, 'r', encoding='utf-8') as f:
|
||||||
|
local_info = yaml.safe_load(f)
|
||||||
|
current_version = str(local_info.get('version', current_version))
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
# 1시간마다 체크 (force=True면 즉시)
|
||||||
|
if not force and AnimeModuleBase._latest_version and (now - AnimeModuleBase._last_update_check < 3600):
|
||||||
|
return {
|
||||||
|
'current': current_version,
|
||||||
|
'latest': AnimeModuleBase._latest_version,
|
||||||
|
'has_update': self._is_newer(AnimeModuleBase._latest_version, current_version)
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = "https://raw.githubusercontent.com/projectdx75/anime_downloader/master/info.yaml"
|
||||||
|
res = requests.get(url, timeout=5)
|
||||||
|
if res.status_code == 200:
|
||||||
|
import yaml
|
||||||
|
data = yaml.safe_load(res.text)
|
||||||
|
AnimeModuleBase._latest_version = str(data.get('version', ''))
|
||||||
|
AnimeModuleBase._last_update_check = now
|
||||||
|
|
||||||
|
return {
|
||||||
|
'current': current_version,
|
||||||
|
'latest': AnimeModuleBase._latest_version,
|
||||||
|
'has_update': self._is_newer(AnimeModuleBase._latest_version, current_version)
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
self.P.logger.error(f"Update check failed: {e}")
|
||||||
|
|
||||||
|
return {
|
||||||
|
'current': current_version,
|
||||||
|
'latest': AnimeModuleBase._latest_version or current_version,
|
||||||
|
'has_update': False
|
||||||
|
}
|
||||||
|
|
||||||
|
def _is_newer(self, latest, current):
|
||||||
|
"""버전 비교 (0.7.8 vs 0.7.7)"""
|
||||||
|
if not latest or not current: return False
|
||||||
|
try:
|
||||||
|
l_parts = [int(p) for p in latest.split('.')]
|
||||||
|
c_parts = [int(p) for p in current.split('.')]
|
||||||
|
return l_parts > c_parts
|
||||||
|
except:
|
||||||
|
return latest != current
|
||||||
|
|
||||||
|
def reload_plugin(self):
|
||||||
|
"""플러그인 모듈 핫 리로드"""
|
||||||
|
import sys
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
try:
|
||||||
|
package_name = self.P.package_name
|
||||||
|
self.P.logger.info(f"플러그인 리로드 시작: {package_name}")
|
||||||
|
|
||||||
|
# 관련 모듈 찾기 및 리로드
|
||||||
|
modules_to_reload = []
|
||||||
|
for module_name in list(sys.modules.keys()):
|
||||||
|
if module_name.startswith(package_name):
|
||||||
|
modules_to_reload.append(module_name)
|
||||||
|
|
||||||
|
# 의존성 역순으로 정렬 (깊은 모듈 먼저)
|
||||||
|
modules_to_reload.sort(key=lambda x: x.count('.'), reverse=True)
|
||||||
|
|
||||||
|
for module_name in modules_to_reload:
|
||||||
|
try:
|
||||||
|
module = sys.modules[module_name]
|
||||||
|
importlib.reload(module)
|
||||||
|
self.P.logger.debug(f"Reloaded: {module_name}")
|
||||||
|
except Exception as e:
|
||||||
|
self.P.logger.warning(f"Failed to reload {module_name}: {e}")
|
||||||
|
|
||||||
|
self.P.logger.info(f"플러그인 모듈 [{package_name}] 리로드 완료")
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
self.P.logger.error(f"모듈 리로드 중 실패: {str(e)}")
|
||||||
|
self.P.logger.error(traceback.format_exc())
|
||||||
|
return False
|
||||||
|
|||||||
@@ -8,7 +8,12 @@
|
|||||||
<div class="glass-card p-4">
|
<div class="glass-card p-4">
|
||||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<h2 class="text-white font-weight-bold"><i class="bi bi-gear-fill mr-2"></i>Anilife 설정</h2>
|
<h2 class="text-white font-weight-bold"><i class="bi bi-gear-fill mr-2"></i>Anilife 설정</h2>
|
||||||
{{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}}
|
<div>
|
||||||
|
<button type="button" class="btn btn-outline-info btn-sm mr-2" id="btn-self-update" title="최신 버전으로 업데이트">
|
||||||
|
<i class="bi bi-arrow-repeat"></i> 업데이트
|
||||||
|
</button>
|
||||||
|
{{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ macros.m_row_start('5') }}
|
{{ macros.m_row_start('5') }}
|
||||||
@@ -709,6 +714,37 @@ function getDragAfterElement(container, x) {
|
|||||||
return [...container.querySelectorAll('.tag-chip:not(.dragging)')].reduce((c, el) => { var box = el.getBoundingClientRect(); var offset = x - box.left - box.width/2; return (offset < 0 && offset > c.offset) ? {offset, element: el} : c; }, {offset: Number.NEGATIVE_INFINITY}).element;
|
return [...container.querySelectorAll('.tag-chip:not(.dragging)')].reduce((c, el) => { var box = el.getBoundingClientRect(); var offset = x - box.left - box.width/2; return (offset < 0 && offset > c.offset) ? {offset, element: el} : c; }, {offset: Number.NEGATIVE_INFINITY}).element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ======================================
|
||||||
|
// 자가 업데이트 기능
|
||||||
|
// ======================================
|
||||||
|
$('#btn-self-update').on('click', function() {
|
||||||
|
if (!confirm('최신 코드를 다운로드하고 플러그인을 리로드하시겠습니까?')) return;
|
||||||
|
|
||||||
|
var btn = $(this);
|
||||||
|
var originalHTML = btn.html();
|
||||||
|
btn.prop('disabled', true).html('<i class="bi bi-arrow-repeat spin"></i> 업데이트 중...');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/' + package_name + '/ajax/' + sub + '/self_update',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(ret) {
|
||||||
|
if (ret.ret === 'success') {
|
||||||
|
$.notify('<strong>업데이트 완료!</strong> 페이지를 새로고침합니다.', {type: 'success'});
|
||||||
|
setTimeout(function() { location.reload(); }, 1500);
|
||||||
|
} else {
|
||||||
|
$.notify('<strong>업데이트 실패: ' + ret.msg + '</strong>', {type: 'danger'});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
$.notify('<strong>업데이트 중 오류 발생</strong>', {type: 'danger'});
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
btn.prop('disabled', false).html(originalHTML);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -8,7 +8,12 @@
|
|||||||
<div class="glass-card p-4">
|
<div class="glass-card p-4">
|
||||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
<h2 class="text-white font-weight-bold"><i class="bi bi-gear-fill mr-2"></i>Linkkf 설정</h2>
|
<h2 class="text-white font-weight-bold"><i class="bi bi-gear-fill mr-2"></i>Linkkf 설정</h2>
|
||||||
{{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}}
|
<div>
|
||||||
|
<button type="button" class="btn btn-outline-info btn-sm mr-2" id="btn-self-update" title="최신 버전으로 업데이트">
|
||||||
|
<i class="bi bi-arrow-repeat"></i> 업데이트
|
||||||
|
</button>
|
||||||
|
{{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ macros.m_row_start('5') }}
|
{{ macros.m_row_start('5') }}
|
||||||
@@ -553,5 +558,36 @@ $('#tag_chips_container').on('dragover', function(e) { e.preventDefault(); var a
|
|||||||
function getDragAfterElement(container, x) {
|
function getDragAfterElement(container, x) {
|
||||||
return [...container.querySelectorAll('.tag-chip:not(.dragging)')].reduce((c, el) => { var box = el.getBoundingClientRect(); var offset = x - box.left - box.width/2; return (offset < 0 && offset > c.offset) ? {offset, element: el} : c; }, {offset: Number.NEGATIVE_INFINITY}).element;
|
return [...container.querySelectorAll('.tag-chip:not(.dragging)')].reduce((c, el) => { var box = el.getBoundingClientRect(); var offset = x - box.left - box.width/2; return (offset < 0 && offset > c.offset) ? {offset, element: el} : c; }, {offset: Number.NEGATIVE_INFINITY}).element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ======================================
|
||||||
|
// 자가 업데이트 기능
|
||||||
|
// ======================================
|
||||||
|
$('#btn-self-update').on('click', function() {
|
||||||
|
if (!confirm('최신 코드를 다운로드하고 플러그인을 리로드하시겠습니까?')) return;
|
||||||
|
|
||||||
|
var btn = $(this);
|
||||||
|
var originalHTML = btn.html();
|
||||||
|
btn.prop('disabled', true).html('<i class="bi bi-arrow-repeat spin"></i> 업데이트 중...');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/' + package_name + '/ajax/' + sub + '/self_update',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(ret) {
|
||||||
|
if (ret.ret === 'success') {
|
||||||
|
$.notify('<strong>업데이트 완료!</strong> 페이지를 새로고침합니다.', {type: 'success'});
|
||||||
|
setTimeout(function() { location.reload(); }, 1500);
|
||||||
|
} else {
|
||||||
|
$.notify('<strong>업데이트 실패: ' + ret.msg + '</strong>', {type: 'danger'});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
$.notify('<strong>업데이트 중 오류 발생</strong>', {type: 'danger'});
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
btn.prop('disabled', false).html(originalHTML);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -17,6 +17,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ohli24-header-right">
|
<div class="ohli24-header-right">
|
||||||
|
<button type="button" class="btn btn-outline-info btn-sm mr-2" id="btn-self-update" title="최신 버전으로 업데이트">
|
||||||
|
<i class="bi bi-arrow-repeat"></i> 업데이트
|
||||||
|
</button>
|
||||||
{{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}}
|
{{ macros.m_button_group([['globalSettingSaveBtn', '설정 저장']])}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -855,6 +858,37 @@ function getDragAfterElement(container, x) {
|
|||||||
}, { offset: Number.NEGATIVE_INFINITY }).element;
|
}, { offset: Number.NEGATIVE_INFINITY }).element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ======================================
|
||||||
|
// 자가 업데이트 기능
|
||||||
|
// ======================================
|
||||||
|
$('#btn-self-update').on('click', function() {
|
||||||
|
if (!confirm('최신 코드를 다운로드하고 플러그인을 리로드하시겠습니까?')) return;
|
||||||
|
|
||||||
|
var btn = $(this);
|
||||||
|
var originalHTML = btn.html();
|
||||||
|
btn.prop('disabled', true).html('<i class="bi bi-arrow-repeat spin"></i> 업데이트 중...');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/' + package_name + '/ajax/' + sub + '/self_update',
|
||||||
|
type: 'POST',
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(ret) {
|
||||||
|
if (ret.ret === 'success') {
|
||||||
|
$.notify('<strong>업데이트 완료!</strong> 페이지를 새로고침합니다.', {type: 'success'});
|
||||||
|
setTimeout(function() { location.reload(); }, 1500);
|
||||||
|
} else {
|
||||||
|
$.notify('<strong>업데이트 실패: ' + ret.msg + '</strong>', {type: 'danger'});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
$.notify('<strong>업데이트 중 오류 발생</strong>', {type: 'danger'});
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
btn.prop('disabled', false).html(originalHTML);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user