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

fix: apply correct mimeType in iOS #1023

Merged
merged 7 commits into from
Nov 21, 2023
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
20 changes: 10 additions & 10 deletions ios/CozyShare/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ class ShareViewController: UIViewController {
if error == nil, let url = data as? URL, let this = self {
// this.redirectToHostApp(type: .media)
// Always copy
let fileExtension = this.getExtension(from: url, type: .video)
let newName = UUID().uuidString
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent("\(newName).\(fileExtension)")
let copied = this.copyFile(at: url, to: newPath)
let newName = this.getFileName(from :url)
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent("\(newName)")
let copied = this.copyFile(at: url, to: newPath)

if(copied) {
this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .image))
}
Expand All @@ -120,12 +120,12 @@ class ShareViewController: UIViewController {
if error == nil, let url = data as? URL, let this = self {

// Always copy
let fileExtension = this.getExtension(from: url, type: .video)
let newName = UUID().uuidString
let newName = this.getFileName(from :url)
let newPath = FileManager.default
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent("\(newName).\(fileExtension)")
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent("\(newName)")
let copied = this.copyFile(at: url, to: newPath)

if(copied) {
guard let sharedFile = this.getSharedMediaFile(forVideo: newPath) else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,16 @@ index 2ad1da2..97348a2 100644
}

protected getFileNames(
diff --git a/node_modules/@mythologi/react-native-receive-sharing-intent/src/utils.ts b/node_modules/@mythologi/react-native-receive-sharing-intent/src/utils.ts
index 60e638e..62540db 100644
--- a/node_modules/@mythologi/react-native-receive-sharing-intent/src/utils.ts
+++ b/node_modules/@mythologi/react-native-receive-sharing-intent/src/utils.ts
@@ -61,7 +61,7 @@ class Utils implements IUtils {
const type = Object.entries(MimeTypes).find(
(mime) => mime[0] === extension
);
- if (type) return type[0];
+ if (type) return type[1];
return '';
};
}
54 changes: 34 additions & 20 deletions src/app/domain/osReceive/fixtures/AndroidReceivedFile.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
export const AndroidReceivedFileFixture = {
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A23',
extension: 'pdf',
fileName: '123_foo_bar_baz_45.67EUR.pdf',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf',
mimeType: 'application/pdf',
subject: null
}
export const AndroidReceivedFileFixture = [
{
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A23',
extension: 'pdf',
fileName: '123_foo_bar_baz_45.67EUR.pdf',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf',
mimeType: 'application/pdf',
subject: null
}
]

export const AndroidReceivedFileFixture2 = {
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A32',
extension: 'pdf',
fileName: '321_foo_bar_baz_45.67EUR.pdf',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/321_foo_bar_baz_45.67EUR.pdf',
mimeType: 'application/pdf',
subject: null
}
export const AndroidReceivedFileFixtures = [
{
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A23',
extension: 'pdf',
fileName: '123_foo_bar_baz_45.67EUR.pdf',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf',
mimeType: 'application/pdf',
subject: null
},
{
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A232',
extension: 'jpg',
fileName: '123_foo_bar_baz_452.67EUR.jpg',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR2.jpg',
mimeType: 'image/jpeg',
subject: null
}
]
45 changes: 45 additions & 0 deletions src/app/domain/osReceive/fixtures/iOSReceivedFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export const iOSReceivedFileFixture = [
{
contentUri: null,
extension: 'pdf',
fileName: 'Carte_Alan.pdf',
filePath:
'file:///Users/anc/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf',
mimeType: 'application/pdf',
text: null,
weblink: null
}
]

export const iOSReceivedFileFixtures = [
{
contentUri: null,
extension: 'pdf',
fileName: 'Carte_Alan.pdf',
filePath:
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf',
mimeType: 'application/pdf',
text: null,
weblink: null
},
{
contentUri: null,
extension: 'jpg',
fileName: 'Carte_Alan2.jpg',
filePath:
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan2.jpg',
mimeType: 'image/jpeg',
text: null,
weblink: null
},
{
contentUri: null,
extension: 'jpg',
fileName: 'Carte_Alan3.jpg',
filePath:
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan3.jpg',
mimeType: '.jpg',
text: null,
weblink: null
}
]
2 changes: 1 addition & 1 deletion src/app/domain/osReceive/models/OsReceiveState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum OsReceiveFileStatus {

export interface OsReceiveFile {
name: string
file: ReceivedFile
file: ReceivedFile & { fromFlagship: true }
status: OsReceiveFileStatus
handledTimestamp?: number // Unix timestamp representing when the file was handled
source?: string // base64 of the file content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ const jpgFile: OsReceiveFile = {
mimeType: '.jpg',
contentUri: null,
fileName: 'SOME_IMAGE.JPG',
extension: 'JPG'
extension: 'JPG',
fromFlagship: true
},
status: 0
}
Expand All @@ -424,7 +425,8 @@ const pdfFile: OsReceiveFile = {
mimeType: '.pdf',
contentUri: null,
fileName: 'SOME_IMAGE.PDF',
extension: 'PDF'
extension: 'PDF',
fromFlagship: true
},
status: 0
}
166 changes: 166 additions & 0 deletions src/app/domain/osReceive/services/OsReceiveData.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { _onReceiveFiles } from '/app/domain/osReceive/services/OsReceiveData'
import {
AndroidReceivedFileFixture,
AndroidReceivedFileFixtures
} from '/app/domain/osReceive/fixtures/AndroidReceivedFile'
import {
iOSReceivedFileFixture,
iOSReceivedFileFixtures
} from '/app/domain/osReceive/fixtures/iOSReceivedFile'
import { OsReceiveFile } from '/app/domain/osReceive/models/OsReceiveState'

describe('onReceiveFiles', () => {
beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation(() => {
// noop
})
})

it('should process Android file correctly', () => {
const result = _onReceiveFiles(AndroidReceivedFileFixture)

const expected: OsReceiveFile[] = [
{
file: {
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A23',
extension: 'pdf',
fileName: '123_foo_bar_baz_45.67EUR.pdf',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf',
fromFlagship: true,
mimeType: 'application/pdf',
subject: null
},
name: '123_foo_bar_baz_45.67EUR.pdf',
status: 0,
type: 'application/pdf'
}
]

expect(result).toEqual(expected)
})

it('should process Android files correctly', () => {
const result = _onReceiveFiles(AndroidReceivedFileFixtures)

const expected: OsReceiveFile[] = [
{
file: {
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A23',
extension: 'pdf',
fileName: '123_foo_bar_baz_45.67EUR.pdf',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR.pdf',
fromFlagship: true,
mimeType: 'application/pdf',
subject: null
},
name: '123_foo_bar_baz_45.67EUR.pdf',
status: 0,
type: 'application/pdf'
},
{
file: {
contentUri:
'content://com.android.providers.downloads.documents/document/foo%1A232',
extension: 'jpg',
fileName: '123_foo_bar_baz_452.67EUR.jpg',
filePath:
'/data/user/0/io.cozy.flagship.mobile/cache/123_foo_bar_baz_45.67EUR2.jpg',
fromFlagship: true,
mimeType: 'image/jpeg',
subject: null
},
name: '123_foo_bar_baz_452.67EUR.jpg',
status: 0,
type: 'image/jpeg'
}
]

expect(result).toEqual(expected)
})

it('should process iOS file correctly', () => {
const result = _onReceiveFiles(iOSReceivedFileFixture)

const expected: OsReceiveFile[] = [
{
file: {
contentUri: null,
extension: 'pdf',
fileName: 'Carte_Alan.pdf',
filePath:
'file:///Users/anc/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf',
fromFlagship: true,
mimeType: 'application/pdf',
text: null,
weblink: null
},
name: 'Carte_Alan.pdf',
status: 0,
type: 'application/pdf'
}
]

expect(result).toEqual(expected)
})

it('should process iOS files correctly', () => {
const result = _onReceiveFiles(iOSReceivedFileFixtures)

const expected: OsReceiveFile[] = [
{
file: {
contentUri: null,
extension: 'pdf',
fileName: 'Carte_Alan.pdf',
filePath:
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan.pdf',
fromFlagship: true,
mimeType: 'application/pdf',
text: null,
weblink: null
},
name: 'Carte_Alan.pdf',
status: 0,
type: 'application/pdf'
},
{
file: {
contentUri: null,
extension: 'jpg',
fileName: 'Carte_Alan2.jpg',
filePath:
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan2.jpg',
fromFlagship: true,
mimeType: 'image/jpeg',
text: null,
weblink: null
},
name: 'Carte_Alan2.jpg',
status: 0,
type: 'image/jpeg'
},
{
file: {
contentUri: null,
extension: 'jpg',
fileName: 'Carte_Alan3.jpg',
filePath:
'file:///Users/toto/Library/Developer/CoreSimulator/Devices/AE73D485-F700-46F2-900B-713E046D6B51/data/Containers/Shared/AppGroup/7B75CC01-AE21-4949-9E2E-0DC1F63D0C15/Carte_Alan3.jpg',
fromFlagship: true,
mimeType: 'image/jpeg',
text: null,
weblink: null
},
name: 'Carte_Alan3.jpg',
status: 0,
type: 'image/jpeg'
}
]

expect(result).toEqual(expected)
})
})
Loading
Loading