更新gitee分享文件位置链接

This commit is contained in:
caojiezi2003 2024-08-05 10:23:12 +08:00
parent 348b5668fd
commit 40e77fef15

View File

@ -5,91 +5,91 @@ import utils from '../utils';
import userSvc from '../userSvc'; import userSvc from '../userSvc';
export default new Provider({ export default new Provider({
id: 'giteegist', id: 'giteegist',
name: 'GiteeGist', name: 'GiteeGist',
getToken({ sub }) { getToken({ sub }) {
return store.getters['data/giteeTokensBySub'][sub]; return store.getters['data/giteeTokensBySub'][sub];
}, },
getLocationUrl({ gistId }) { getLocationUrl({ gistId }) {
return `https://gitee.com/mafgwo/codes/${gistId}`; return `https://gitee.com/caojiezi2003/codes/${gistId}`;
}, },
getLocationDescription({ filename }) { getLocationDescription({ filename }) {
return filename; return filename;
}, },
async downloadContent(token, syncLocation) { async downloadContent(token, syncLocation) {
const content = await giteeHelper.downloadGist({ const content = await giteeHelper.downloadGist({
...syncLocation, ...syncLocation,
token, token,
}); });
return Provider.parseContent(content, `${syncLocation.fileId}/content`); return Provider.parseContent(content, `${syncLocation.fileId}/content`);
}, },
async uploadContent(token, content, syncLocation) { async uploadContent(token, content, syncLocation) {
const file = store.state.file.itemsById[syncLocation.fileId]; const file = store.state.file.itemsById[syncLocation.fileId];
const description = utils.sanitizeName(file && file.name); const description = utils.sanitizeName(file && file.name);
const gist = await giteeHelper.uploadGist({ const gist = await giteeHelper.uploadGist({
...syncLocation, ...syncLocation,
token, token,
description, description,
content: Provider.serializeContent(content), content: Provider.serializeContent(content),
}); });
return { return {
...syncLocation, ...syncLocation,
gistId: gist.id, gistId: gist.id,
}; };
}, },
async publish(token, html, metadata, publishLocation) { async publish(token, html, metadata, publishLocation) {
const gist = await giteeHelper.uploadGist({ const gist = await giteeHelper.uploadGist({
...publishLocation, ...publishLocation,
token, token,
description: metadata.title, description: metadata.title,
content: html, content: html,
}); });
return { return {
...publishLocation, ...publishLocation,
gistId: gist.id, gistId: gist.id,
}; };
}, },
makeLocation(token, filename, isPublic, gistId) { makeLocation(token, filename, isPublic, gistId) {
return { return {
providerId: this.id, providerId: this.id,
sub: token.sub, sub: token.sub,
filename, filename,
isPublic, isPublic,
gistId, gistId,
}; };
}, },
async listFileRevisions({ token, syncLocation }) { async listFileRevisions({ token, syncLocation }) {
const entries = await giteeHelper.getGistCommits({ const entries = await giteeHelper.getGistCommits({
...syncLocation, ...syncLocation,
token, token,
}); });
return entries.map((entry) => { return entries.map((entry) => {
const sub = `${giteeHelper.subPrefix}:${entry.user.id}`; const sub = `${giteeHelper.subPrefix}:${entry.user.id}`;
userSvc.addUserInfo({ id: sub, name: entry.user.login, imageUrl: entry.user.avatar_url }); userSvc.addUserInfo({ id: sub, name: entry.user.login, imageUrl: entry.user.avatar_url });
return { return {
sub, sub,
id: entry.version, id: entry.version,
message: entry.commit && entry.commit.message, message: entry.commit && entry.commit.message,
created: new Date(entry.committed_at).getTime(), created: new Date(entry.committed_at).getTime(),
}; };
}); });
}, },
async loadFileRevision() { async loadFileRevision() {
// Revision are already loaded // Revision are already loaded
return false; return false;
}, },
// async getFileRevisionContent({ // async getFileRevisionContent({
// token, // token,
// contentId, // contentId,
// syncLocation, // syncLocation,
// revisionId, // revisionId,
// }) { // }) {
// const data = await giteeHelper.downloadGistRevision({ // const data = await giteeHelper.downloadGistRevision({
// ...syncLocation, // ...syncLocation,
// token, // token,
// sha: revisionId, // sha: revisionId,
// }); // });
// return Provider.parseContent(data, contentId); // return Provider.parseContent(data, contentId);
// }, // },
}); });