-
\ No newline at end of file
+
diff --git a/src/store/index.js b/src/store/index.js
index 73dfb8d..386af38 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -19,7 +19,7 @@ axios.interceptors.response.use(
const actions = {
reconnect(context) {
- axios.post(GalleryManageUrl + "/reconnect", {
+ axios.post(GalleryManageUrl + "/reconnect", null, {
params: {
AuthCode: context.state.AuthCode
}
@@ -181,7 +181,9 @@ const actions = {
if(gallery.images !== undefined && gallery.images.length !== 0)
context.commit("_setReadingGallery", gallery)
else
- axios.post(GalleryManageUrl + "/cache?url=" + gallery.link).then((res) => {
+ return axios.post(GalleryManageUrl + "/cache", null, {
+ params: {url: gallery.link, AuthCode: context.state.AuthCode}
+ }).then((res) => {
if (res.data.result === 'success') {
gallery.pages = res.data.data.pages
setTimeout(() => {
@@ -243,7 +245,10 @@ const mutations = {
//处理名字
task.shortName = getShortname(task.name)
if(task.thumb_link.trim() !== '')
- task.thumb_link = GalleryManageUrl + "/ehThumbnail?path=" + task.thumb_link
+ task.thumb_link = buildGalleryManageUrl("/ehThumbnail", {
+ path: task.thumb_link,
+ AuthCode: state.AuthCode
+ })
else
delete task.thumb_link
@@ -396,7 +401,10 @@ const mutations = {
if(gallery.images === undefined) {
gallery.images = []
for(let i=1; i<=gallery.pages; i++)
- gallery.images.push(GalleryManageUrl + "/onlineImage/" + i + "?gid=" + gallery.gid);
+ gallery.images.push(buildGalleryManageUrl("/onlineImage/" + i, {
+ gid: gallery.gid,
+ AuthCode: state.AuthCode
+ }));
}
state.readingGallery = gallery
state.isReading = true;
@@ -499,6 +507,10 @@ function buildGalleryDownloadUrl(gid, AuthCode){
return GalleryManageUrl + "/file/" + gid + ".zip?" + params.toString()
}
+function buildGalleryManageUrl(path, params){
+ return GalleryManageUrl + path + "?" + new URLSearchParams(params).toString()
+}
+
function confirmCurrentTask(state){
switch (state.category){
case 'myDownload':
diff --git a/tests/store.test.mjs b/tests/store.test.mjs
index 3f020b2..374864a 100644
--- a/tests/store.test.mjs
+++ b/tests/store.test.mjs
@@ -8,9 +8,11 @@ function fixture() {
.replace(/^import .*$/gm, '')
.replace('export default new vuex.Store(', 'globalThis.store = new vuex.Store(')
const messages = []
+ const showMessage = message => messages.push(message)
+ showMessage.error = message => messages.push(message)
const axios = {interceptors: {response: {use() {}}}}
const context = vm.createContext({axios, vuex: {Store: function (config) {Object.assign(this, config)}},
- ElMessage: message => messages.push(message), URLSearchParams, console,
+ ElMessage: showMessage, URLSearchParams, console,
qs: {stringify: () => ''}})
vm.runInContext(code, context)
const store = context.store
@@ -48,3 +50,46 @@ test('submission reloads persisted status without duplicating a completed task',
assert.equal(store.state.totalGalleryTask[0].status, '下载完成')
assert.equal(store.state.chosenGallery, false)
})
+
+test('gallery management subrequests carry the active auth code', async () => {
+ const {store, axios, api} = fixture()
+ store.state.AuthCode = 'test-auth'
+ let call
+ axios.post = async (...args) => {
+ call = args
+ return {data: {result: args[0].endsWith('/cache') ? 'failure' : 'success', data: 'expected test response'}}
+ }
+ await store.actions.reconnect(api)
+ assert.equal(call[0], 'https://downloader.lionwebsite.xyz/GalleryManage/reconnect')
+ assert.equal(call[1], null)
+ assert.equal(call[2].params.AuthCode, 'test-auth')
+
+ await store.actions.readOnlineGallery(api, {link: 'https://example.org/g/1/key/', images: []})
+ assert.equal(call[0], 'https://downloader.lionwebsite.xyz/GalleryManage/cache')
+ assert.equal(call[1], null)
+ assert.deepEqual({...call[2].params}, {
+ url: 'https://example.org/g/1/key/',
+ AuthCode: 'test-auth'
+ })
+})
+
+test('thumbnail and online image URLs carry the active auth code', () => {
+ const {store} = fixture()
+ store.state.AuthCode = 'code with spaces'
+ store.mutations._updateGalleryTasks(store.state, [{
+ gid: 123,
+ name: 'sample',
+ status: '已提交',
+ thumb_link: 'https://example.org/thumb?a=1&b=2',
+ createTime: 1,
+ downloader: 7
+ }])
+ const thumbnail = new URL(store.state.totalGalleryTask[0].thumb_link)
+ assert.equal(thumbnail.searchParams.get('AuthCode'), 'code with spaces')
+ assert.equal(thumbnail.searchParams.get('path'), 'https://example.org/thumb?a=1&b=2')
+
+ store.mutations._setReadingGallery(store.state, {gid: 123, pages: 1})
+ const image = new URL(store.state.readingGallery.images[0])
+ assert.equal(image.searchParams.get('gid'), '123')
+ assert.equal(image.searchParams.get('AuthCode'), 'code with spaces')
+})