Skip to content

Commit

Permalink
test(snapshot): remove obsolete snap
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmcg committed May 26, 2022
1 parent be5a7c4 commit 4de5bbf
Show file tree
Hide file tree
Showing 33 changed files with 300 additions and 1,611 deletions.
7 changes: 1 addition & 6 deletions components/ui/Chat/Embeds/File/File.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
<TypographySubtitle :size="6" :text="`${file.name}`" />
<TypographyText :text="`${file.type} - ${getFileSize}`" />
</div>
<a
:href="file.url"
target="_blank"
class="button is-primary"
data-cy="chat-file"
>
<a @click="download" class="button is-primary" data-cy="chat-file">
<download-icon size="1x" class="download" />
</a>
</template>
Expand Down
9 changes: 9 additions & 0 deletions components/ui/Chat/Embeds/File/File.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export default Vue.extend({
return isMimeEmbeddableImage(this.file.type)
},
},
methods: {
download() {
this.$TextileManager.sharedBucket?.pullFile(
this.file.id,
this.file.name,
this.file.size,
)
},
},
})
</script>
<style lang="less" scoped src="./File.less"></style>
7 changes: 4 additions & 3 deletions components/ui/Chat/Image/Image.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<template src="./Image.html" />
<template src="./Image.html"></template>
<script lang="ts">
import Vue, { PropType } from 'vue'
import { ImageIcon, DownloadIcon } from 'satellite-lucide-icons'
import { FileMessage, ImageMessage } from '~/types/textile/mailbox'
import { FileMessage } from '~/types/textile/mailbox'
// @ts-ignore
import placeholderImage from '~/assets/svg/mascot/sad_curious.svg'
export default Vue.extend({
Expand All @@ -20,7 +21,7 @@ export default Vue.extend({
default: false,
},
image: {
type: Object as PropType<ImageMessage>,
type: Object as PropType<FileMessage>,
required: true,
},
},
Expand Down
7 changes: 1 addition & 6 deletions components/views/chat/message/Message.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@
({{$t('ui.edited')}})
</span>
</template>
<UiChatImage
v-if="message.type === 'image'"
:image="message.payload"
alt=""
/>
<MessageGlyph
v-else-if="message.type === 'glyph'"
v-if="message.type === 'glyph'"
:source="message.payload"
:pack="message.pack"
/>
Expand Down
10 changes: 5 additions & 5 deletions components/views/chat/message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ export default Vue.extend({
this.$toast.show(this.$t('ui.copied') as string)
},
saveImage() {
const a = document.createElement('a')
a.setAttribute('type', 'hidden')
a.setAttribute('download', 'download')
a.href = URL.createObjectURL(this.blob)
a.click()
this.$TextileManager.sharedBucket?.pullFile(
this.message.payload.id,
this.message.payload.name,
this.message.payload.size,
)
},
/**
* @method toPng
Expand Down
8 changes: 6 additions & 2 deletions components/views/files/controls/Controls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export default Vue.extend({
return
}
this.text = ''
await this.$TextileManager.bucket?.updateIndex(this.$FileSystem.export)
await this.$TextileManager.privateBucket?.updateIndex(
this.$FileSystem.export,
)
this.$store.commit('ui/setFilesUploadStatus', '')
this.$emit('forceRender')
Expand Down Expand Up @@ -185,7 +187,9 @@ export default Vue.extend({
'ui/setFilesUploadStatus',
this.$t('pages.files.status.index'),
)
await this.$TextileManager.bucket?.updateIndex(this.$FileSystem.export)
await this.$TextileManager.privateBucket?.updateIndex(
this.$FileSystem.export,
)
}
this.$store.commit('ui/setFilesUploadStatus', '')
Expand Down
4 changes: 3 additions & 1 deletion components/views/files/rename/Rename.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export default Vue.extend({
'ui/setFilesUploadStatus',
this.$t('pages.files.status.index'),
)
await this.$TextileManager.bucket?.updateIndex(this.$FileSystem.export)
await this.$TextileManager.privateBucket?.updateIndex(
this.$FileSystem.export,
)
this.$store.commit('ui/setFilesUploadStatus', '')
},
},
Expand Down
2 changes: 1 addition & 1 deletion components/views/files/view/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default Vue.extend({
.slice(((this.file.name.lastIndexOf('.') - 1) >>> 0) + 2)
.toLowerCase()
await this.$TextileManager.bucket?.pullFile(
await this.$TextileManager.privateBucket?.pullFile(
this.file.id,
this.file.extension === fileExt
? this.file.name
Expand Down
2 changes: 1 addition & 1 deletion libraries/Files/TextileFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class TextileFileSystem extends FilSystem {
* @returns {PrivateBucket} bucket global to upload files to textile
*/
get bucket(): PrivateBucket {
return Vue.prototype.$TextileManager.bucket
return Vue.prototype.$TextileManager.privateBucket
}

/**
Expand Down
17 changes: 13 additions & 4 deletions libraries/Files/remote/abstracts/Bucket.abstract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Buckets, Root } from '@textile/buckets'
import { createWriteStream } from 'streamsaver'
import { Config } from '~/config'
import { FileSystemExport } from '~/libraries/Files/types/filesystem'
import {
FileSystemExport,
SharedBucketIndex,
} from '~/libraries/Files/types/filesystem'
import { TextileInitializationData } from '~/types/textile/manager'
import { RFM } from '~/libraries/Files/remote/abstracts/RFM.abstract'

Expand All @@ -16,15 +19,15 @@ export abstract class BucketAbstract extends RFM {
this._textile = textile
}

abstract get index(): FileSystemExport | undefined
abstract get index(): FileSystemExport | SharedBucketIndex | undefined

/**
* @method getBucket
* @description Initializes bucket
* @param param0 bucket name and encrypted status
* @returns a promise that resolves when the initialization completes
*/
async getBucket({ name, encrypted }: { name: string; encrypted: boolean }) {
async getBucket({ name, encrypted }: { name: string; encrypted?: boolean }) {
if (!Config.textile.key) {
throw new Error('Textile key not found')
}
Expand Down Expand Up @@ -53,8 +56,13 @@ export abstract class BucketAbstract extends RFM {
* @param {File} file file to be uploaded
* @param {string} path uuid to maintain unique bucket paths
* @param {Function} progressCallback used to show progress meter in componment that calls this method
* @returns {string} path to file, used moreso for shared buckets
*/
async pushFile(file: File, path: string, progressCallback: Function) {
async pushFile(
file: File,
path: string,
progressCallback: Function,
): Promise<string> {
if (!this._buckets || !this._key) {
throw new Error('Bucket or bucket key not found')
}
Expand All @@ -74,6 +82,7 @@ export abstract class BucketAbstract extends RFM {
},
)
this._root = res.root
return res.path.path
}

private _getStream(file: File) {
Expand Down
9 changes: 6 additions & 3 deletions libraries/Files/remote/abstracts/RFM.abstract.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Remote file management
import { FileSystemErrors } from '../../errors/Errors'
import { FileSystemExport } from '~/libraries/Files/types/filesystem'
import {
FileSystemExport,
SharedBucketIndex,
} from '~/libraries/Files/types/filesystem'

export abstract class RFM {
constructor() {
if (this.constructor.name === 'RFM')
throw new Error(FileSystemErrors.RFM_ABSTRACT_ONLY)
}

abstract updateIndex(index: FileSystemExport): void
abstract updateIndex(index: FileSystemExport | SharedBucketIndex): void

abstract get index(): FileSystemExport | undefined
abstract get index(): FileSystemExport | SharedBucketIndex | undefined

abstract pullFile(id: string, name: string, size: number): void

Expand Down
31 changes: 8 additions & 23 deletions libraries/Files/remote/textile/PrivateBucket.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { BucketAbstract } from '../abstracts/Bucket.abstract'
import Vue from 'vue'
import { BucketAbstract } from '~/libraries/Files/remote/abstracts/Bucket.abstract'
import { Config } from '~/config'
import {
FileSystemExport,
FILESYSTEM_TYPE,
} from '~/libraries/Files/types/filesystem'
import { FileSystemExport } from '~/libraries/Files/types/filesystem'

export class PrivateBucket extends BucketAbstract {
private _index?: FileSystemExport

/**
* @getter
* @returns file system export data
Expand All @@ -19,18 +18,11 @@ export class PrivateBucket extends BucketAbstract {
* @method init
* @description Initializes bucket
* @param name bucket name
* @returns {Promise<FileSystemExport>} a promise that resolves when the initialization completes
*/
async init({
name,
encrypted,
}: {
name: string
encrypted: boolean
}): Promise<FileSystemExport> {
async init({ name, encrypted }: { name: string; encrypted: boolean }) {
await this.getBucket({ name, encrypted })
if (!this._buckets || !this._key) {
throw new Error('woah')
throw new Error('Bucket or bucket key not found')
}
try {
const data = []
Expand All @@ -45,16 +37,9 @@ export class PrivateBucket extends BucketAbstract {
type: 'application/json',
}).text(),
)

if (!this._index) throw new Error('Index not found')

return this._index
Vue.prototype.$Logger.log('File System', 'Initialized')
} catch (e) {
return {
type: FILESYSTEM_TYPE.DEFAULT,
version: 1,
content: [],
}
Vue.prototype.$Logger.log('File System', 'Not Found')
}
}

Expand Down
70 changes: 70 additions & 0 deletions libraries/Files/remote/textile/SharedBucket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { BucketAbstract } from '~/libraries/Files/remote/abstracts/Bucket.abstract'
import { Config } from '~/config'
import {
FILESYSTEM_TYPE,
SharedBucketIndex,
} from '~/libraries/Files/types/filesystem'

export class SharedBucket extends BucketAbstract {
private _index: SharedBucketIndex = {
type: FILESYSTEM_TYPE.DEFAULT,
version: 1,
content: [],
}

/**
* @getter
* @returns file system export data
*/
get index(): SharedBucketIndex {
return this._index
}

/**
* @method init
* @description Initializes bucket
* @param name bucket name
*/
async init({ name }: { name: string }) {
await this.getBucket({ name })
if (!this._buckets || !this._key) {
throw new Error('Bucket or bucket key not found')
}
// todo - add index tracking capabilities to shared bucket
// try {
// const data = []
// for await (const bytes of this._buckets.pullPath(
// this._key,
// Config.textile.fsTable,
// )) {
// data.push(bytes)
// }
// this._index = JSON.parse(
// await new Blob(data, {
// type: 'application/json',
// }).text(),
// )
// } catch (e) {
// console.log(e)
// }
}

/**
* @method updateIndex
* @param index SharedBucketIndex
* @description sets index data and root
*/
async updateIndex(index: SharedBucketIndex) {
if (!this._buckets || !this._key) {
throw new Error('Bucket or bucket key not found')
}
this._index = index
const res = await this._buckets.pushPath(
this._key,
Config.textile.fsTable,
Buffer.from(JSON.stringify(index)),
{ root: this._root },
)
this._root = res.root
}
}
14 changes: 7 additions & 7 deletions libraries/Files/test/TextileFileSystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Vue.prototype.$TextileManager = new TextileManager()
describe('', () => {
Vue.prototype.$TextileManager = new TextileManager()
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.bucket = jest.fn()
TMConstructor.bucket.removeFile = jest.fn()
TMConstructor.bucket.pushFile = jest.fn()
TMConstructor.privateBucket = jest.fn()
TMConstructor.privateBucket.removeFile = jest.fn()
TMConstructor.privateBucket.pushFile = jest.fn()
const TextileFileSystemConstructor = new TextileFileSystem()
const inst = TextileFileSystemConstructor
const state = inst.bucket
Expand All @@ -24,7 +24,7 @@ describe('', () => {

test('TextileFileSystem.removeFile', async () => {
await inst.removeFile('TestFile.png')
expect(TMConstructor.bucket.removeFile).toHaveBeenCalled()
expect(TMConstructor.privateBucket.removeFile).toHaveBeenCalled()
})

test('TextileFileSystem.uploadFile', async () => {
Expand All @@ -41,7 +41,7 @@ describe('', () => {
}

await inst.uploadFile(testFile, nsfw, cbFunction)
expect(TMConstructor.bucket.pushFile).toHaveBeenCalled()
expect(TMConstructor.privateBucket.pushFile).toHaveBeenCalled()
})

// This test is skipped due to it exceeding the timeout (5000 ms).
Expand All @@ -59,7 +59,7 @@ describe('', () => {
}

await inst.uploadFile(testBlobFile, nsfw, cbFunction)
expect(TMConstructor.bucket.pushFile).toHaveBeenCalled()
expect(TMConstructor.privateBucket.pushFile).toHaveBeenCalled()
})

test.skip('TextileFileSystem.uploadFile for png file', async () => {
Expand All @@ -75,6 +75,6 @@ describe('', () => {
}

await inst.uploadFile(testBlobFile, nsfw, cbFunction)
expect(TMConstructor.bucket.pushFile).toHaveBeenCalled()
expect(TMConstructor.privateBucket.pushFile).toHaveBeenCalled()
})
})
Loading

0 comments on commit 4de5bbf

Please sign in to comment.