Skip to content

Commit

Permalink
feat(storage): add initial firebase storage
Browse files Browse the repository at this point in the history
Signed-off-by: Hosung Kim [email protected]
  • Loading branch information
hs0225 committed Aug 2, 2023
1 parent cd242ee commit 924c56e
Show file tree
Hide file tree
Showing 48 changed files with 3,979 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins:
firebase_core: ["tv-7.0"]
firebase_database: []
firebase_storage: []
firebase_storage: ["tv-7.0"]
cloud_functions: []
2 changes: 1 addition & 1 deletion packages/firebase_core/tizen/build_def.prop
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PREBUILD_COMMAND = ./tar_url.sh \
https://github.com/daeye0n/gooddaytocode/archive/refs/tags/v10.4.0-draft-4.tar.gz \
https://raw.githubusercontent.com/hs0225/download/firebase-sdk/firebaseSDK-tizen-1.0.1.tar.gz\
&& ./cp_firebase_libs.sh
3 changes: 3 additions & 0 deletions packages/firebase_storage/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
BasedOnStyle: Google
---
28 changes: 28 additions & 0 deletions packages/firebase_storage/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# VS Code related
.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/
3 changes: 3 additions & 0 deletions packages/firebase_storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial release.
61 changes: 61 additions & 0 deletions packages/firebase_storage/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
```
Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

```
Copyright 2017 The Chromium Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

```
Copyright 2019 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
55 changes: 55 additions & 0 deletions packages/firebase_storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# firebase_storage_tizen

A new Flutter plugin project.

## Getting Started

This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.

For help getting started with Flutter development, view the
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

The plugin project was generated without specifying the `--platforms` flag, no platforms are currently supported.
To add platforms, run `flutter create -t plugin --platforms <platforms> .` in this directory.
You can also find a detailed instruction on how to add platforms in the `pubspec.yaml` at https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms.

# Usage

To use this package, you need to include `firebase_storage_tizen` as a dependency alongside `firebase_storage` in your `pubspec.yaml`. Please note that `firebase_storage_tizen` implementation is not officially endorsed for `firebase_storage`.

```yaml
dependencies:
firebase_storage: ^11.0.10
firebase_storage_tizen: ^0.1.0
```
Then you can import `firebase_storage` in your Dart code:

```dart
import 'package:firebase_storage/firebase_storage.dart';
```

## Required privileges

To use this plugin in a Tizen application, you may need to declare the following privileges in your `tizen-manifest.xml` file.

```xml
<privileges>
<privilege>http://tizen.org/privilege/internet</privilege>
</privileges>
```

- `http://tizen.org/privilege/internet` allows the application to access the Internet.

For the details on Tizen privileges, please see [Tizen Docs: API Privileges](https://docs.tizen.org/application/dotnet/get-started/api-privileges).

# Limitations

The following features are currently unavailable as they're not supported by the version of Firebase C++ SDK for Linux that this plugin is currently based on.

- useEmulator method of FirebaseStorage class.
- listAll method of Reference class.
1 change: 1 addition & 0 deletions packages/firebase_storage/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: ../../analysis_options.yaml
42 changes: 42 additions & 0 deletions packages/firebase_storage/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# VS Code related
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
16 changes: 16 additions & 0 deletions packages/firebase_storage/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# firebase_storage_tizen_example

Demonstrates how to use the firebase_storage_tizen plugin.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
10 changes: 10 additions & 0 deletions packages/firebase_storage/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# in the LICENSE file.

include: ../../../analysis_options.yaml
linter:
rules:
avoid_print: false
depend_on_referenced_packages: false
library_private_types_in_public_api: false
1 change: 1 addition & 0 deletions packages/firebase_storage/example/assets/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world
105 changes: 105 additions & 0 deletions packages/firebase_storage/example/integration_test/extratest_e2e.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2023 Samsung Electronics Co., Ltd. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter_test/flutter_test.dart';

import './test_utils.dart';

const String kOkString = 'ok';
final List<int> okStringList = utf8.encode(kOkString);

void setupExtraTests() {
group('$Reference', () {
late FirebaseStorage storage;

setUpAll(() async {
storage = FirebaseStorage.instance;
});

test('getData', () async {
final Reference ref = storage.ref('flutter-tests/ok.txt');

// fix: Ensure reference file has an ok string.
await ref.putString(kOkString);
final bytes = await ref.getData();

List<int> okStringList = utf8.encode(kOkString);
expect(bytes?.length, okStringList.length);
expect(bytes, okStringList);
});

test('getMetadata', () async {
final Reference ref = storage.ref('flutter-tests/ok.txt');

final result = await ref.getMetadata();
expect(result, isA<FullMetadata>());
expect(result.name, 'ok.txt');
});
});

group('ControlTask', () {
late FirebaseStorage storage;

setUpAll(() async {
storage = FirebaseStorage.instance;
});

Future<void> _testPauseTask(Task task) async {
List<TaskSnapshot> snapshots = [];
bool hasError = false;
expect(task.snapshot.state, TaskState.running);

task.snapshotEvents.listen(
(TaskSnapshot snapshot) {
snapshots.add(snapshot);
},
onError: (error) {
hasError = true;
},
cancelOnError: true,
);

await task.snapshotEvents.first;
await Future.delayed(const Duration(milliseconds: 100));

bool? paused = await task.pause();
expect(paused, isTrue);
expect(task.snapshot.state, TaskState.paused);

await Future.delayed(const Duration(milliseconds: 100));
bool? resumed = await task.resume();
expect(resumed, isTrue);
expect(task.snapshot.state, TaskState.running);

TaskSnapshot snapshot = await task;
expect(task.snapshot.state, TaskState.success);
expect(snapshot.state, TaskState.success);

expect(snapshot.totalBytes, snapshot.bytesTransferred);

expect(hasError, false);
}

test('upload pause and resume', () async {
final File file = await createFile('test-file.txt');
final Reference ref = storage.ref('flutter-tests').child('test-file.txt');

await _testPauseTask(ref.putFile(file));
});

test('download pause and resume', () async {
final Directory systemTempDir = Directory.systemTemp;
final File tempFile = File('${systemTempDir.path}/temp-test-file.txt');
if (tempFile.existsSync()) await tempFile.delete();

final Reference ref = storage.ref('flutter-tests').child('test-file.txt');

await _testPauseTask(ref.writeToFile(tempFile));
});
});
}
Loading

0 comments on commit 924c56e

Please sign in to comment.