Skip to content

Commit

Permalink
fix: fix sync bug in Files (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
qq815776412 authored Sep 26, 2024
2 parents f1d590b + 26fc3a9 commit 0a4589f
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 48 deletions.
26 changes: 21 additions & 5 deletions packages/app/src/api/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ const defaultConfig: AxiosRequestConfig = {
}
};

const errorMessages = new Set();
let errorTimeout: any;

const handleError = (message: string) => {
if (!errorMessages.has(message)) {
errorMessages.add(message);
console.error(message);
BtNotify.show({
type: NotifyDefinedType.FAILED,
message: message
});

if (errorTimeout) clearTimeout(errorTimeout);

errorTimeout = setTimeout(() => {
errorMessages.clear();
}, 5000);
}
};

class Fetch {
private instance: AxiosInstance;

Expand Down Expand Up @@ -89,12 +109,8 @@ class Fetch {
return response;
},
(error) => {
console.log('error.message', error.message);
if (error.message !== 'Request blocked') {
BtNotify.show({
type: NotifyDefinedType.FAILED,
message: JSON.stringify(error.message)
});
handleError(JSON.stringify(error.message));
}

if (error.message == InOfflineText()) {
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/api/sync/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class Data extends Origin {
let slotPath = '/';
for (let i = 3; i < splitPath.length; i++) {
const el = splitPath[i];
slotPath += el;
slotPath += el + '/';
}

if (!slotPath.endsWith('/')) {
Expand Down Expand Up @@ -599,7 +599,10 @@ class Data extends Origin {
}

getAttrPath(item: FileItem): string {
return item.path.slice(0, item.path.indexOf('?'));
const path = item.path.slice(0, item.path.indexOf('?'));
const lastIndex = path.lastIndexOf('/');
if (lastIndex === -1) return path;
return path.substring(0, lastIndex);
}

async getFileServerUploadLink(
Expand Down
7 changes: 4 additions & 3 deletions packages/app/src/api/sync/filesFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export function formatSeahub(url: string, data: { dirent_list: any }) {
};

dirent_lists.forEach((el, index) => {
console.log('dirent_listsdirent_lists', el);
const extension = getextension(el.name);
const fileTypeName =
el.type === 'dir' ? i18n.global.t('files.folders') : getFileType(el.name);
const itemPath = `/Seahub/${repo_name}${
el.path || ''
}/?id=${repo_id}&type=${type}&p=${p}`;
const path =
el.type === 'dir' ? el.parent_dir + el.name + '/' : el.parent_dir;
const itemPath = `/Seahub/${repo_name}${path}?id=${repo_id}&type=${type}&p=${p}`;

const obj: FileItem = {
path: itemPath,
Expand Down
6 changes: 1 addition & 5 deletions packages/app/src/api/sync/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,11 @@ export async function fileOperate(

export async function updateFile(item, content, isNative = false) {
const menuStore = useMenuStore();
const pathLen =
item.url.indexOf(menuStore.activeMenu.label) +
menuStore.activeMenu.label.length;
const parent_dir = item.url.slice(pathLen).split('?')[0];
const res = await fetchURL(
`seahub/api2/repos/${menuStore.activeMenu.id}/update-link/?p=/`,
{}
);
const curPath = parent_dir + item.name;
const curPath = item.parentPath + item.name;

const params = {
target_file: curPath,
Expand Down
8 changes: 7 additions & 1 deletion packages/app/src/components/files/files/OperateMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const eventType = reactive<EventType>({
hasCopied: false,
showRename: true,
isHomePage: false,
selectCount: 0
selectCount: 0,
rw: true
});
const filteredContextmenuMenu = computed(() => {
Expand All @@ -80,6 +81,11 @@ watch(
eventType.selectCount = 0;
}
eventType.rw = true;
if (newVal[1] === 'shared' && newVal[2] === 'r') {
eventType.rw = false;
}
const menuHeight = filteredContextmenuMenu.value.length * 36;
if (props.offsetBottom && props.offsetBottom < menuHeight) {
top.value = props.clientY - menuHeight;
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/files/popup/DeleteRepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const submit = async () => {
try {
await dataAPI.deleteRepo(props.item);
submitLoading.value = false;
await menuStore.getSyncMenu();
onDialogOK();
await menuStore.getSyncMenu();
} catch (error) {
submitLoading.value = false;
}
Expand Down
56 changes: 40 additions & 16 deletions packages/app/src/components/files/popup/PopupMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import { useOperateinStore } from './../../../stores/operation';
import ReName from './ReName.vue';
import SelectLocal from './SelectLocal.vue';
import DeleteRepo from './DeleteRepo.vue';
import DeleteDialog from './../../../components/files/prompts/DeleteDialog.vue';
import SyncInfo from './SyncInfo.vue';
import { BtDialog } from '@bytetrade/ui';
import { getParams } from '../../../utils/utils';
import { ref } from 'vue';
import { useI18n } from 'vue-i18n';
Expand Down Expand Up @@ -131,36 +133,43 @@ const checkShardUser = () => {
let selfMenuList = JSON.parse(JSON.stringify(menuList.value));
let newMenuList: any[] = [];
console.log('checkShardUseritem', props.item);
const p = props.item ? getParams(props.item.path, 'p') : 'rw';
const shard_type = props.item && getParams(props.item.path, 'type');
console.log('ppppppp-', p);
for (let i = 0; i < selfMenuList.length; i++) {
const slef = selfMenuList[i];
if (
slef.action === OPERATE_ACTION.SHARE_WITH &&
props.item?.type &&
props.item.type === 'shared'
(props.item.type === 'shared' || shard_type === 'shared')
) {
continue;
}
if (
slef.action === OPERATE_ACTION.EXIT_SHARING &&
props.item?.type &&
props.item.type === 'mine'
(props.item.type === 'shared' || shard_type === 'shared')
) {
continue;
}
if (
slef.action === OPERATE_ACTION.RENAME &&
props.item?.type &&
props.item.type === 'shared'
(props.item.type === 'shared' || shard_type === 'shared')
) {
continue;
}
if (
slef.action === OPERATE_ACTION.DELETE &&
props.item?.type &&
props.item.type === 'shared'
(props.item.type === 'shared' || shard_type === 'shared')
) {
continue;
}
Expand Down Expand Up @@ -269,19 +278,29 @@ const showRename = (e: any) => {
const deleteRepo = async (e: any) => {
const jsonItem = JSON.parse(JSON.stringify(props.item));
console.log('jsonItemjsonItem', jsonItem);
if (props.from === DriveType.Sync) {
try {
const res = await menuStore.fetchShareInfo(jsonItem.repo_id);
const shared_user_emails_length = res.shared_user_emails.length || 0;
$q.dialog({
component: DeleteRepo,
componentProps: {
item: jsonItem,
shared_length: shared_user_emails_length
}
});
if (jsonItem.repo_id) {
const res = await menuStore.fetchShareInfo(jsonItem.repo_id);
const shared_user_emails_length = res.shared_user_emails.length || 0;
$q.dialog({
component: DeleteRepo,
componentProps: {
item: jsonItem,
shared_length: shared_user_emails_length
}
});
} else {
$q.dialog({
component: DeleteDialog,
componentProps: {
item: jsonItem
}
});
}
} catch (error) {
return false;
}
Expand Down Expand Up @@ -330,7 +349,12 @@ const deleteShareRepo = async () => {
})
.then(async (res: any) => {
if (res) {
const path = `seahub/api/v2.1/shared-repos/${props.item?.repo_id}/?share_type=${props.item?.share_type}&user=${props.item?.user_email}`;
let path = '';
if (props.item?.share_type === 'personal') {
path = `seahub/api/v2.1/shared-repos/${props.item?.repo_id}/?share_type=${props.item?.share_type}&user=${props.item?.user_email}`;
} else {
path = `seahub/api/v2.1/shared-repos/${props.item?.repo_id}/?share_type=public`;
}
await seahub.deleteRepo(path);
menuStore.getSyncMenu();
}
Expand Down
13 changes: 10 additions & 3 deletions packages/app/src/components/files/popup/SyncInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { format, useDialogPluginComponent, useQuasar } from 'quasar';
import { formatFileModified } from 'src/utils/file';
import { dataAPIs } from './../../../api';
import { DriveType } from './../../../stores/files';
import TerminusFileIcon from '../../common/TerminusFileIcon.vue';
import TerminusDialogBar from '../../common/TerminusDialogBar.vue';
Expand All @@ -89,8 +91,6 @@ const props = defineProps({
}
});
console.log('propsitem', props.item);
const { dialogRef, onDialogCancel } = useDialogPluginComponent();
const $q = useQuasar();
Expand Down Expand Up @@ -137,7 +137,14 @@ const readOnly = computed(function () {
});
const path = computed(function () {
return `/${props.item?.name}`;
let resPath = '';
if (props.item?.path) {
resPath = dataAPIs(DriveType.Sync).getAttrPath(props.item);
} else {
resPath = `/Seahub/${props.item?.name}`;
}
return resPath;
});
const onCancel = () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/files/prompts/ShareDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@
</q-card-section>

<terminus-dialog-footer
:okText="t('complete')"
:okText="t('buttons.close')"
:cancelText="t('cancel')"
showCancel
:showCancel="false"
@close="onDialogCancel"
@submit="onDialogOk"
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export default {
please_enter_a_library_name: 'Please enter a library name',
exit_sharing_message: 'Do you want to exit sharing?',
all_uploaded_successfully: 'Uploaded successfully',
add_user: 'Add user',
add_user: 'Share to user',

unlock: {
title: 'Unlock',
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/i18n/en-US/old_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export default {
please_enter_a_library_name: 'Please enter a library name',
exit_sharing_message: 'Are you sure you want to exit sharing?',
all_uploaded_successfully: 'All uploaded successfully',
add_user: 'Add User',
add_user: 'Share to user',

unlock: {
title: 'Unlock',
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/i18n/zh-CN/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export default {
please_enter_a_library_name: '请输入库名称',
exit_sharing_message: '是否退出共享?',
all_uploaded_successfully: '上传成功',
add_user: '添加用户',
add_user: '共享用户',
unlock: {
title: '解锁',
vault_unlock_introduce:
Expand Down
22 changes: 22 additions & 0 deletions packages/app/src/pages/Mobile/file/FilesRepoPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ onMounted(async () => {
...res2,
...res3
]).items;
const res = await seahub.fetchMineRepo();
const formatRes = await formatSeahubRepos(route.params.repo, res).items;
filesStore.currentFileList.map((shareItem) => {
const commonItem = formatRes.find((item) => item.name === shareItem.name);
if (commonItem) {
shareItem = commonItem;
}
});
const newFileList: any[] = [];
for (let i = 0; i < filesStore.currentFileList.length; i++) {
let shareItem = filesStore.currentFileList[i];
const commonItem = formatRes.find((item) => item.name === shareItem.name);
if (commonItem) {
shareItem = commonItem;
}
newFileList.push(shareItem);
}
filesStore.currentFileList = newFileList;
}
});
</script>
Expand Down
Loading

0 comments on commit 0a4589f

Please sign in to comment.