Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(buckets): upgrade abstract interfaces, switch chat to use SharedBucket class #3285

Merged
merged 12 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 11 additions & 2 deletions components/ui/Chat/Embeds/File/File.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script lang="ts">
import Vue, { PropType } from 'vue'
import { DownloadIcon, FileIcon } from 'satellite-lucide-icons'
import { FileMessage } from '~/types/textile/mailbox'
import { FileMessagePayload } from './types'
import { isMimeEmbeddableImage } from '~/utilities/FileType'

export default Vue.extend({
Expand All @@ -12,7 +12,7 @@ export default Vue.extend({
},
props: {
file: {
type: Object as PropType<FileMessage>,
type: Object as PropType<FileMessagePayload>,
required: true,
},
},
Expand All @@ -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>
11 changes: 6 additions & 5 deletions components/ui/Chat/Embeds/File/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type FileData = {
filename: String
size: Number
type: String
src: String
export type FileMessagePayload = {
url: string
name: string
size: number
type: string
id: string
}
5 changes: 3 additions & 2 deletions components/ui/Chat/Image/Image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<script lang="ts">
import Vue, { PropType } from 'vue'
import { ImageIcon, DownloadIcon } from 'satellite-lucide-icons'
import { FileMessage } from '~/types/textile/mailbox'
import { FileMessagePayload } from '../Embeds/File/types'
// @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<FileMessage>,
type: Object as PropType<FileMessagePayload>,
required: true,
},
},
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 @@ -196,11 +196,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
19 changes: 8 additions & 11 deletions components/views/files/upload/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { FilePlusIcon, PlusIcon } from 'satellite-lucide-icons'
import Vue, { PropType } from 'vue'
import { mapState } from 'vuex'
import { Config } from '~/config'
import { PropCommonEnum } from '~/libraries/Enums/enums'
import { isHeic } from '~/utilities/FileType'
import { UploadDropItemType } from '~/types/files/file'
Expand Down Expand Up @@ -124,18 +123,16 @@ export default Vue.extend({
}),
)
for (const uploadFile of filesToUpload) {
if (uploadFile.file.size <= Config.nsfwPictureLimit) {
uploadFile.nsfw.checking = true
try {
uploadFile.nsfw.status = await this.$Security.isNSFW(
uploadFile.file,
)
} catch (err) {
uploadFile.nsfw.status = true
uploadFile.nsfw.checking = false
}
uploadFile.nsfw.checking = true
try {
uploadFile.nsfw.status = await this.$Security.isNSFW(
uploadFile.file,
)
} catch (err) {
uploadFile.nsfw.status = true
uploadFile.nsfw.checking = false
}
uploadFile.nsfw.checking = false
this.loadPicture(uploadFile, () =>
this.$store.commit('chat/addFile', {
file: uploadFile,
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 @@ -57,7 +57,7 @@ export default Vue.extend({
.slice(((this.file.name.lastIndexOf('.') - 1) >>> 0) + 2)
.toLowerCase()

await this.$TextileManager.bucket?.pullFileStream(
await this.$TextileManager.personalBucket?.pullFile(
this.file.id,
this.file.extension === fileExt
? this.file.name
Expand Down
5 changes: 3 additions & 2 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export const Config = {
'https://webapi.hub.edge.satellite.one',
groupChatThreadID:
'bafkv7ordeargenxdutqdltvlo6sbfcfdhuvmocrt4qe6kpohrdbrbdi',
fsTable: 'sat.json',
bucketName: 'personal-files',
bucketIndex: 'sat.json',
personalBucket: 'personal-files',
sharedBucket: 'shared-files',
},
ipfs: {
gateway: 'https://satellite.mypinata.cloud/ipfs/',
Expand Down
10 changes: 5 additions & 5 deletions libraries/Files/FilSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DIRECTORY_TYPE } from './types/directory'
import { Fil } from './Fil'
import { Item } from './abstracts/Item.abstract'
import {
FileSystemExport,
PersonalBucketIndex,
ExportItem,
FILESYSTEM_TYPE,
ExportFile,
Expand Down Expand Up @@ -95,9 +95,9 @@ export class FilSystem {

/**
* @getter export
* @returns {FileSystemExport} returns exported filesystem object
* @returns {PersonalBucketIndex} returns exported filesystem object
*/
get export(): FileSystemExport {
get export(): PersonalBucketIndex {
return {
type: FILESYSTEM_TYPE.DEFAULT,
version: ++this._version,
Expand Down Expand Up @@ -242,10 +242,10 @@ export class FilSystem {

/**
* @method import
* @param {FileSystemExport} fs
* @param {PersonalBucketIndex} fs
* @description sets global file system based on parameter. will be fetched from Bucket
*/
public async import(fs: FileSystemExport) {
public async import(fs: PersonalBucketIndex) {
for (const item of fs.content) {
await this.importChildren(item)
}
Expand Down
8 changes: 4 additions & 4 deletions libraries/Files/TextileFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Vue from 'vue'
import skaler from 'skaler'
import { FilSystem } from './FilSystem'
import { FILE_TYPE } from './types/file'
import { Bucket } from './remote/textile/Bucket'
import { PersonalBucket } from './remote/textile/PersonalBucket'
import { Config } from '~/config'
import { EnvInfo } from '~/utilities/EnvInfo'
import { mimeType, isHeic, isMimeEmbeddableImage } from '~/utilities/FileType'
Expand All @@ -13,10 +13,10 @@ const convert = require('heic-convert')
export class TextileFileSystem extends FilSystem {
/**
* @getter bucket
* @returns {Bucket} bucket global to upload files to textile
* @returns {PersonalBucket} bucket global to upload files to textile
*/
get bucket(): Bucket {
return Vue.prototype.$TextileManager.bucket
get bucket(): PersonalBucket {
return Vue.prototype.$TextileManager.personalBucket
}

/**
Expand Down
2 changes: 0 additions & 2 deletions libraries/Files/errors/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ export enum TextileErrors {

export enum FileSystemErrors {
// internal
METHOD_MISSING = 'Method not implemented.',
RFM_ABSTRACT_ONLY = 'RFM class is Abstract. It can only be extended',
ITEM_ABSTRACT_ONLY = 'Item class is Abstract. It can only be extended',
// user facing - Item
NO_EMPTY_STRING = 'pages.files.errors.no_empty',
Expand Down
19 changes: 19 additions & 0 deletions libraries/Files/interface/RFM.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Remote file management
import {
PersonalBucketIndex,
SharedBucketIndex,
} from '~/libraries/Files/types/filesystem'

export interface RFM {
get index(): PersonalBucketIndex | SharedBucketIndex | undefined

getBucket({ name, encrypted }: { name: string; encrypted?: boolean }): void

pushFile(file: File, path: string, progressCallback: Function): void

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

removeFile(name: string): void

updateIndex(index: PersonalBucketIndex | SharedBucketIndex): void
}
Loading