Skip to content

Commit

Permalink
Fix sidebar for not synced files
Browse files Browse the repository at this point in the history
Resolves #394
  • Loading branch information
ggodlewski authored and horner committed Oct 29, 2023
1 parent d55f008 commit 45530d3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
25 changes: 21 additions & 4 deletions apps/ui/src/pages/GDocsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
</div>
</td>
</tr>
<tr v-else>
<td>
<div class="d-flex" data-bs-toggle="tooltip" data-bs-placement="bottom" :title="selectedFile.path">
<strong>Path:&nbsp;</strong>
<span class="text-overflow">
<span class="small text-muted">Not synced</span>
</span>
<span class="small text-muted text-end">
<button class="btn btn-white bg-white text-primary btn-sm" v-if="selectedFile.id" @click="syncSingle($event, selectedFile)" title="Sync single">
<i class="fa-solid fa-rotate" :class="{'fa-spin': syncing}"></i>
</button>
</span>
</div>
</td>
</tr>

<tr v-if="selectedFile.modifiedTime">
<td class="text-overflow">
Expand Down Expand Up @@ -138,7 +153,7 @@
</div>
</div>

<div class="card-header d-flex" v-if="!syncing">
<div class="card-header d-flex" v-if="!syncing && selectedFile.path">
Git
<ul class="nav flex-row flex-grow-1 flex-shrink-0 justify-content-end">
<ToolButton
Expand Down Expand Up @@ -178,7 +193,7 @@
/>
</ul>
</div>
<GitFooter class="mt-3 mb-3" v-if="!syncing">
<GitFooter class="mt-3 mb-3" v-if="!syncing && selectedFile.path">
<div v-if="selectedFile.status">
<div class="input-groups">
<textarea v-grow class="form-control" placeholder="Commit message" v-model="commitMsg"></textarea>
Expand Down Expand Up @@ -255,8 +270,8 @@ export default {
}
};
},
created() {
this.fetch();
async created() {
await this.fetch();
},
computed: {
change() {
Expand Down Expand Up @@ -378,6 +393,8 @@ export default {
if (err.code === 404) {
this.shareEmail = err.share_email;
this.notRegistered = true;
} else {
throw err;
}
}
}
Expand Down
38 changes: 33 additions & 5 deletions src/containers/server/routes/GoogleDriveController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {getContentFileService} from '../../transform/utils';
import {GoogleTreeProcessor} from '../../google_folder/GoogleTreeProcessor';
import {UserAuthClient} from '../../../google/AuthClient';
import {filterParams} from '../../../google/driveFetch';
import {GoogleDriveService} from '../../../google/GoogleDriveService';
import {redirError} from '../auth';

export class GoogleDriveController extends Controller {

Expand Down Expand Up @@ -60,7 +62,7 @@ export class GoogleDriveController extends Controller {
@RouteGet('/:driveId/:fileId')
@RouteResponse('stream')
@RouteErrorHandler(new ShareErrorHandler())
async getDocs(@RouteParamPath('driveId') driveId: string, @RouteParamPath('fileId') fileId: string) {
async getDocs(@RouteParamPath('driveId') driveId: string, @RouteParamPath('fileId') fileId: string, @RouteParamUser() user) {
const googleFileSystem = await this.filesService.getSubFileService(driveId, '/');
const userConfigService = new UserConfigService(googleFileSystem);
await userConfigService.load();
Expand All @@ -71,18 +73,44 @@ export class GoogleDriveController extends Controller {
await markdownTreeProcessor.load();
const [foundTreeItem] = await markdownTreeProcessor.findById(fileId);

const contentDir = (userConfigService.config.transform_subdir || '').startsWith('/') ? userConfigService.config.transform_subdir : undefined;
this.res.setHeader('wgd-content-dir', contentDir || '');
this.res.setHeader('wgd-google-id', fileId);

if (!foundTreeItem) {
const googleDriveService = new GoogleDriveService(this.logger, null);
const auth = {
async getAccessToken(): Promise<string> {
return user.google_access_token;
}
};
try {
const file = await googleDriveService.getFile(auth, fileId);
if (file) {
this.res.setHeader('wgd-google-parent-id', file.parentId || '');
this.res.setHeader('wgd-google-version', file.version || '');
this.res.setHeader('wgd-google-modified-time', file.modifiedTime || '');
this.res.setHeader('wgd-mime-type', file.mimeType || '');
this.res.setHeader('wgd-last-author', file.lastAuthor || '');
this.res.setHeader('Content-type', file.mimeType);

this.res.send('Not synced');
return;
}
} catch (err) {
if (err.status === 401) {
throw redirError(this.req, err.message);
return;
}
}

this.res.status(404).send({ message: 'No local' });
return;
}

const treeItem = addPreviewUrl(userConfigService.config.hugo_theme, driveId)(foundTreeItem);

const contentDir = (userConfigService.config.transform_subdir || '').startsWith('/') ? userConfigService.config.transform_subdir : undefined;

this.res.setHeader('wgd-content-dir', contentDir || '');
this.res.setHeader('wgd-google-parent-id', treeItem.parentId || '');
this.res.setHeader('wgd-google-id', treeItem.id || '');
this.res.setHeader('wgd-google-version', treeItem.version || '');
this.res.setHeader('wgd-google-modified-time', treeItem.modifiedTime || '');
this.res.setHeader('wgd-path', treeItem.path || '');
Expand Down

0 comments on commit 45530d3

Please sign in to comment.