Skip to content

Commit e7ab987

Browse files
authored
Merge pull request #393 from GitLiveApp/start-off-adding-firebase-storage
Adding firebase storage
2 parents 2fc9c04 + 012de30 commit e7ab987

File tree

23 files changed

+796
-3
lines changed

23 files changed

+796
-3
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
run: ./gradlew :firebase-firestore:publish
4343
- name: Publish Firebase Functions
4444
run: ./gradlew :firebase-functions:publish
45+
- name: Publish Firebase Storage
46+
run: ./gradlew :firebase-storage:publish
4547
- name: Publish Firebase Installations
4648
run: ./gradlew :firebase-installations:publish
4749
- name: Publish Firebase Performance

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The following libraries are available for the various Firebase products.
1717
| [Cloud Firestore](https://firebase.google.com/docs/firestore) | [`dev.gitlive:firebase-firestore:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-firestore/1.8.0/pom) | [![60%](https://img.shields.io/badge/-60%25-orange?style=flat-square)](/firebase-firestore/src/commonMain/kotlin/dev/gitlive/firebase/firestore/firestore.kt) |
1818
| [Cloud Functions](https://firebase.google.com/docs/functions) | [`dev.gitlive:firebase-functions:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-functions/1.8.0/pom) | [![80%](https://img.shields.io/badge/-80%25-green?style=flat-square)](/firebase-functions/src/commonMain/kotlin/dev/gitlive/firebase/functions/functions.kt) |
1919
| [Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) | [`dev.gitlive:firebase-messaging:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-messaging/1.8.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
20-
| [Cloud Storage](https://firebase.google.com/docs/storage) | [`dev.gitlive:firebase-storage:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-storage/1.8.0/pom) | ![0%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
20+
| [Cloud Storage](https://firebase.google.com/docs/storage) | [`dev.gitlive:firebase-storage:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-storage/1.8.0/pom) | ![40%](https://img.shields.io/badge/-0%25-lightgrey?style=flat-square) |
2121
| [Installations](https://firebase.google.com/docs/projects/manage-installations) | [`dev.gitlive:firebase-installations:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-installations/1.8.0/pom) | [![90%](https://img.shields.io/badge/-90%25-green?style=flat-square)](/firebase-installations/src/commonMain/kotlin/dev/gitlive/firebase/installations/installations.kt) |
2222
| [Remote Config](https://firebase.google.com/docs/remote-config) | [`dev.gitlive:firebase-config:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-config/1.8.0/pom) | ![20%](https://img.shields.io/badge/-20%25-orange?style=flat-square) |
2323
| [Performance](https://firebase.google.com/docs/perf-mon) | [`dev.gitlive:firebase-perf:1.8.0`](https://search.maven.org/artifact/dev.gitlive/firebase-perf/1.8.0/pom) | ![1%](https://img.shields.io/badge/-1%25-orange?style=flat-square) |

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ tasks {
4444
"firebase-firestore:updateVersion", "firebase-firestore:updateDependencyVersion",
4545
"firebase-functions:updateVersion", "firebase-functions:updateDependencyVersion",
4646
"firebase-installations:updateVersion", "firebase-installations:updateDependencyVersion",
47-
"firebase-perf:updateVersion", "firebase-perf:updateDependencyVersion"
47+
"firebase-perf:updateVersion", "firebase-perf:updateDependencyVersion",
48+
"firebase-storage:updateVersion", "firebase-storage:updateDependencyVersion"
4849
)
4950
}
5051
}

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals.kt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
package dev.gitlive.firebase
88

9+
import kotlinx.serialization.StringFormat
10+
import org.khronos.webgl.Uint8Array
11+
import org.w3c.files.Blob
12+
import org.w3c.files.File
913
import kotlin.js.Json
1014
import kotlin.js.Promise
1115

@@ -19,6 +23,7 @@ external object firebase {
1923
fun functions(region: String? = definedExternally): functions.Functions
2024
fun database(url: String? = definedExternally): database.Database
2125
fun firestore(): firestore.Firestore
26+
fun storage(): storage.Storage
2227
}
2328

2429
interface Options {
@@ -502,6 +507,108 @@ external object firebase {
502507
}
503508
}
504509

510+
fun storage(): storage.Storage
511+
512+
object storage {
513+
514+
open class Storage {
515+
val maxOperationRetryTime: Double
516+
val maxUploadRetryTime: Double
517+
518+
fun setMaxOperationRetryTime(time: Double): Unit
519+
fun setMaxUploadRetryTime(time: Double): Unit
520+
fun useEmulator(host: String, port: Int)
521+
}
522+
523+
open class Reference {
524+
val bucket: String
525+
val fullPath: String
526+
val name: String
527+
val parent: Reference?
528+
val root: Reference
529+
val storage: Storage
530+
531+
fun child(path: String): Reference
532+
fun delete(): Promise<Unit>
533+
fun getDownloadURL(): Promise<String>
534+
fun getMetadata(): Promise<FullMetadata>
535+
fun list(options: ListOptions? = definedExternally): Promise<ListResult>
536+
fun listAll(): Promise<ListResult>
537+
fun put(data: Blob, metadata: UploadMetadata? = definedExternally): UploadTask
538+
fun put(data: Uint8Array, metadata: UploadMetadata? = definedExternally): UploadTask
539+
fun put(data: File, metadata: UploadMetadata? = definedExternally): UploadTask
540+
fun putString(data: String, format: StringFormat? = definedExternally, metadata: UploadMetadata? = definedExternally): UploadTask
541+
fun updateMetadata(metadata: SettableMetadata): Promise<FullMetadata>
542+
}
543+
544+
open class FullMetadata {
545+
val bucket: String
546+
val fullPath: String
547+
val generation: String
548+
val metageneration: String
549+
val name: String
550+
val size: Number
551+
val timeCreated: String
552+
val updated: String
553+
val customMetadata: Json
554+
}
555+
556+
open class ListOptions {
557+
val maxResults: Number
558+
val pageToken: String
559+
}
560+
561+
open class ListResult {
562+
val items: Array<Reference>
563+
val nextPageToken: String
564+
val prefixes: Array<Reference>
565+
}
566+
567+
open class SettableMetadata {
568+
var cacheControl: String?
569+
var contentDisposition: String?
570+
var contentEncoding: String?
571+
var contentLanguage: String?
572+
var contentType: String?
573+
var customMetadata: Json?
574+
}
575+
576+
open class UploadMetadata {
577+
var cacheControl: String?
578+
var contentDisposition: String?
579+
var contentEncoding: String?
580+
var contentLanguage: String?
581+
var contentType: String?
582+
var customMetadata: Json?
583+
}
584+
585+
open class UploadTask {
586+
val snapshot: UploadTaskSnapshot
587+
588+
fun cancel(): Boolean
589+
fun pause(): Boolean
590+
fun resume(): Boolean
591+
fun on(event: String, next: (snapshot: UploadTaskSnapshot) -> Unit, error: (a: FirebaseStorageError) -> Unit, complete: () -> Unit): () -> Unit
592+
}
593+
594+
open class UploadTaskSnapshot {
595+
val bytesTransferred: Number
596+
val metadata: FullMetadata
597+
val ref: Reference
598+
val state: String
599+
val task: UploadTask
600+
val totalBytes: Number
601+
}
602+
603+
open class FirebaseStorageError {
604+
val code: String
605+
val message: String
606+
val name: String
607+
val stack: String?
608+
}
609+
610+
}
611+
505612
fun remoteConfig(app: App? = definedExternally): remoteConfig.RemoteConfig
506613

507614
object remoteConfig {

firebase-common/src/jsMain/kotlin/dev/gitlive/firebase/externals2.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ external object remoteConfig
3232
@JsName("default")
3333
external object performance
3434

35+
@JsModule("firebase/compat/storage")
36+
@JsName("default")
37+
external object storage
38+
3539
typealias SnapshotCallback = (data: firebase.database.DataSnapshot, b: String?) -> Unit
3640

3741
operator fun firebase.functions.HttpsCallable.invoke() = asDynamic()() as Promise<firebase.functions.HttpsCallableResult>

firebase-installations/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ kotlin {
5050
cocoapods {
5151
ios.deploymentTarget = "11.0"
5252
framework {
53-
baseName = "FirebaseFunctions"
53+
baseName = "FirebaseInstallations"
5454
}
5555
noPodspec()
5656
pod("FirebaseInstallations") {

firebase-storage/build.gradle.kts

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
* Copyright (c) 2023 GitLive Ltd. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
version = project.property("firebase-storage.version") as String
6+
7+
plugins {
8+
id("com.android.library")
9+
kotlin("native.cocoapods")
10+
kotlin("multiplatform")
11+
}
12+
13+
android {
14+
compileSdk = property("targetSdkVersion") as Int
15+
defaultConfig {
16+
minSdk = property("minSdkVersion") as Int
17+
targetSdk = property("targetSdkVersion") as Int
18+
}
19+
sourceSets {
20+
getByName("main") {
21+
manifest.srcFile("src/androidMain/AndroidManifest.xml")
22+
}
23+
}
24+
testOptions {
25+
unitTests.apply {
26+
isIncludeAndroidResources = true
27+
}
28+
}
29+
packagingOptions {
30+
resources.pickFirsts.add("META-INF/kotlinx-serialization-core.kotlin_module")
31+
resources.pickFirsts.add("META-INF/AL2.0")
32+
resources.pickFirsts.add("META-INF/LGPL2.1")
33+
}
34+
lint {
35+
abortOnError = false
36+
}
37+
}
38+
39+
val supportIosTarget = project.property("skipIosTarget") != "true"
40+
41+
kotlin {
42+
43+
android {
44+
publishAllLibraryVariants()
45+
}
46+
47+
if (supportIosTarget) {
48+
ios()
49+
iosSimulatorArm64()
50+
cocoapods {
51+
ios.deploymentTarget = "11.0"
52+
framework {
53+
baseName = "FirebaseStorage"
54+
}
55+
noPodspec()
56+
pod("FirebaseStorage") {
57+
version = "10.7.0"
58+
}
59+
}
60+
}
61+
62+
js {
63+
useCommonJs()
64+
nodejs {
65+
testTask {
66+
useKarma {
67+
useChromeHeadless()
68+
}
69+
}
70+
}
71+
browser {
72+
testTask {
73+
useKarma {
74+
useChromeHeadless()
75+
}
76+
}
77+
}
78+
}
79+
80+
sourceSets {
81+
all {
82+
languageSettings.apply {
83+
apiVersion = "1.8"
84+
languageVersion = "1.8"
85+
progressiveMode = true
86+
}
87+
}
88+
89+
val commonMain by getting {
90+
dependencies {
91+
api(project(":firebase-app"))
92+
implementation(project(":firebase-common"))
93+
}
94+
}
95+
96+
val androidMain by getting {
97+
dependencies {
98+
api("com.google.firebase:firebase-storage")
99+
}
100+
}
101+
102+
if (supportIosTarget) {
103+
val iosMain by getting
104+
val iosSimulatorArm64Main by getting
105+
iosSimulatorArm64Main.dependsOn(iosMain)
106+
val iosTest by sourceSets.getting
107+
val iosSimulatorArm64Test by getting
108+
iosSimulatorArm64Test.dependsOn(iosTest)
109+
}
110+
111+
val jsMain by getting
112+
}
113+
}
114+
115+
if (project.property("firebase-storage.skipIosTests") == "true") {
116+
tasks.forEach {
117+
if (it.name.contains("ios", true) && it.name.contains("test", true)) { it.enabled = false }
118+
}
119+
}
120+
121+
if (project.property("firebase-storage.skipJsTests") == "true") {
122+
tasks.forEach {
123+
if (it.name.contains("js", true) && it.name.contains("test", true)) { it.enabled = false }
124+
}
125+
}
126+
127+
signing {
128+
val signingKey: String? by project
129+
val signingPassword: String? by project
130+
useInMemoryPgpKeys(signingKey, signingPassword)
131+
// sign(publishing.publications)
132+
}

firebase-storage/firebase_storage.podspec

Whitespace-only changes.

firebase-storage/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@gitlive/firebase-storage",
3+
"version": "1.8.1",
4+
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
5+
"main": "firebase-storage.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/GitLiveApp/firebase-kotlin-sdk.git"
12+
},
13+
"keywords": [
14+
"kotlin",
15+
"multiplatform",
16+
"kotlin-js",
17+
"firebase"
18+
],
19+
"author": "dev.gitlive",
20+
"license": "Apache-2.0",
21+
"bugs": {
22+
"url": "https://github.com/GitLiveApp/firebase-kotlin-sdk/issues"
23+
},
24+
"homepage": "https://github.com/GitLiveApp/firebase-kotlin-sdk",
25+
"dependencies": {
26+
"@gitlive/firebase-app": "1.8.1",
27+
"firebase": "9.19.1",
28+
"kotlin": "1.6.10",
29+
"kotlinx-coroutines-core": "1.6.1-native-mt"
30+
}
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="dev.gitlive.firebase.storage">
3+
4+
<application android:usesCleartextTraffic="true" />
5+
</manifest>

0 commit comments

Comments
 (0)