How could i make my .json files read-write except read-only? - post

I made a website with next.js and deploy it with vercel. When i tried to make post action to my api's i take that error:
2023-02-17T00:54:35.670Z 94b0f453-0bfc-486b-ab0a-d36c86b0e9c4 ERROR Error: EROFS: read-only file system, open '/var/task/public/database/azalar.json'
at Object.openSync (node:fs:600:3)
at Object.writeFileSync (node:fs:2221:35)
at handler (/var/task/.next/server/pages/api/auth/register.js:106:50)
at Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:372:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:488:9)
at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:751:37)
at async Router.execute (/var/task/node_modules/next/dist/server/router.js:253:36)
at async NextNodeServer.run (/var/task/node_modules/next/dist/server/base-server.js:384:29)
at async NextNodeServer.handleRequest (/var/task/node_modules/next/dist/server/base-server.js:322:20) {
errno: -30,
syscall: 'open',
code: 'EROFS',
path: '/var/task/public/database/azalar.json'
}
after a research i learn it causes from that files are read-only and i don't know how to change that.
i try to solve this problem with allowing somethings on github repository but honestly i don't understand nor could. I set settings such that:
enter image description here
enter image description here
enter image description here
So how can i make my .json files to read-write? And how should i set these values?

Related

How to read config file in electronjs app

It's my first time using Electron JS and nodejs. I've built a small app that reads some records from a database and updates them. Everything is working fine. I have a config file with the database credentials but when I build a portable win app, I cannot figure out how to read the config file that I would like to place next to the exe. I would like to have easy access to the file, so I could run the same app on different databases.
Can anyone tell me if what I want is possible and how? I already tried to get the exe location but I couldn't. I also read a lot of topics here but nothing seems to solve my problem (I might be doing something wrong).
I'm using electron-builder to build my app.
Thanks in advance.
Edit #1
My Config file is
{
"user" :"X",
"password" :"X",
"server":"X",
"database":"X",
"options":
{
"trustedconnection": true,
"enableArithAbort" : true,
"trustServerCertificate": true
}
}
This is what I've and works when I run the project with npm start
const configRootPath = path.resolve(__dirname,'dbConfig.json');
dbConfig = JSON.parse(fs.readFileSync(configRootPath, { encoding: 'utf-8' }));
However, when I build it, the app is looking for the file in another location different from the one where the executable is.
Use of Electron's app.getPath(name) function will get you the path(s) you are after, irrespective of which OS (Operating System) you are using.
Unless your application writes your dbConfig.json file, it may be difficult for your user to understand exactly where they should place their database config file as each OS will run and store your application data in a different directory. You would need to be explicit to the user as to where to place their config file(s). Alternatively, your application could create the config file(s) on the user's behalf (automatically or through a html form) and save it to a location 'known' to the application.
A common place where application specific config files are stored is in the user's application data directory. With the application name automatically amended to the directory, it can be found as shown below.
const electronApp = require('electron').app;
let appUserDataPath = electronApp.getPath('userData');
console.log(appUserDataPath );
In your use case, the below would apply.
const electronApp = require('electron').app;
const nodeFs = require('fs');
const nodePath = require('path');
const configRootPath = nodePath.join(electronApp.getPath('userData'), 'dbConfig.json');
dbConfig = JSON.parse(nodeFs.readFileSync(configRootPath, 'utf-8'));
console.log(configRootPath);
console.log(dbConfig);
You can try electron-store to store config.
Electron doesn't have a built-in way to persist user preferences and other data. This module handles that for you, so you can focus on building your app. The data is saved in a JSON file named config.json in app.getPath('userData').

Copy a DriveItem but overwrite

I want to copy and overwrite the existing file but cannot do it without getting the error nameAlreadyExists .
As a workaround I seem to have to download it into a stream and then reupload it.
The code is as per the API
await graphClient.Sites.Root.Drives[documentLibraryId].Items[fileId]
.Copy(newFileName, parentReference)
.Request()
.PostAsync();
As a workaround I may have to download the file into a strea and then upload it like as per the following which seems to work
await RetryWithExponentialBackoff.RunAsync(async () =>
{
uploadSession = await graphClient.Drives[driveId]
.Root
.ItemWithPath(filePath)
.CreateUploadSession()
.Request()
.PostAsync();
});
Usually you just need to set the microsoft.graph.conflictBehavior to replace. This works fine with functions such as moving. However, the Api ignores the specified conflict behavior with the copy function. More information on the bug here: link to github issue. It does not seem to be a priority for Microsoft, since the bug was reported over a year ago and nothing happened since. So you will most likely need a workaround.
Another idea for a workaround:
Copy the DriveItem to the target document library or folder, but use for example a combination of the current date and the drive item id instead of the desired file name newFileName to make sure, that you not get a conflict with any existing file.
Change the copied DriveItem's name to the desired file name newFileName, e. g.:
PATCH https://graph.microsoft.com/v1.0/sites/siteId/drives/driveId/items/itemId
{
"name": "newFileName",
"#microsoft.graph.conflictBehavior":"replace"
}
In my tests, this replaced the existing file with the name newFileName with the copied file.
With this workaround, you do not need to download and reupload the file. Thus, the performance should be better. However, the user may wonder about weird file names.

How to read and write a text file in Flutter

How do you read text from a file and write text to a file?
I've been learning about how to read and write text to and from a file. I found another question about reading from assets, but that is not the same. I will add my answer below from what I learned from the documentation.
Setup
Add the following plugin in pubspec.yaml:
dependencies:
path_provider: ^1.6.27
Update the version number to whatever is current.
And import it in your code.
import 'package:path_provider/path_provider.dart';
You also have to import dart:io to use the File class.
import 'dart:io';
Writing to a text file
_write(String text) async {
final Directory directory = await getApplicationDocumentsDirectory();
final File file = File('${directory.path}/my_file.txt');
await file.writeAsString(text);
}
Reading from a text file
Future<String> _read() async {
String text;
try {
final Directory directory = await getApplicationDocumentsDirectory();
final File file = File('${directory.path}/my_file.txt');
text = await file.readAsString();
} catch (e) {
print("Couldn't read file");
}
return text;
}
Notes
You can also get the path string with join(directory.path, 'my_file.txt') but you need to import 'package:path/path.dart'.
Flutter's Official Documentation of Reading and Writing Files
This works for iOS, Android, Linux and MacOS but not for web.
As additional info to #Suragch's answer, if you want to find the file you created, you can do as the images show:
And then inside that data folder, go again to a folder named data and search for your package, and then go to:
If you happen to create new files, in order to be able to see them, just right click and click Synchronize.
An another way to pull the file from the device is by using adb pull command. You can find the file path by debugging the code and then use adb pull command. adb is located in Android SDK -> platform-tools directory.
./adb pull /storage/emulated/0/Android/data/com.innovate.storage.storage_sample/files/sample.txt ~/Downloads
#Suragch 's answer is right. Except the version of path_provider that you want to use now is:
path_provider: ^2.0.9

GitHub API: Cannot reliably add files to repository

I experience a very weird error with the GitHub API using the Octokit Ruby library. Only sometimes API requests to add new files to a repository fail with the following message:
Octokit::UnprocessableEntity: PUT https://api.github.com/repos/organization/repo/contents/config.xml: 422 - Invalid request.
"sha" wasn't supplied. // See: https://developer.github.com/v3/repos/contents/#update-a-file
from C:/Dev/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/octokit-4.8.0/lib/octokit/response/raise_error.rb:16:in `on_complete'
Here is how I am trying to upload the contents of an entire folder to GitHub:
Dir.glob(folder + '/**/*') do |path|
next if File.directory?(path)
octokit_client.create_contents 'organization/repo', path.sub("#{folder}/", ''), '🎉', File.read(path), branch: 'master'
end
If an error occurs, it does so with the first attempt to upload a file.
Edit:
I found that the error only occurs when the first file uploaded is a .xml file.
Additionally I often get ...
Octokit::RepositoryUnavailable
PUT https://api.github.com/repos/organization/repo/contents/icon/_60x60_at1x.png: 403 - Repository access blocked
... for other files but the same repository as well.
What am I doing wrong?
Make sure you don't have a file with the same name in the folder.
In this case, you are editing a file and not creating one.

Team Foundation Build Activitie "DownloadFiles" is giving error

I am customizing the default build process template in TFS 2010.
i am using "DownloadFiles" build activity and in server path i have given "$/TFS/Libraries/Foo.DLL", when i run the execute definition its throwing error as "Access to the path '\ServerName\SharedFolder\BuildName\TempFolder' is denied.".
But when i give server path as "$/TFS/Libraries" its downloading all the files in Libraries folder into shared TempFolder.
But i need do download only one file. Please help..
Thanks in advance..
Now, DownloadFiles does work for a whole folder only:
ServerPath="$/proj/path" - works great, all is downloaded to LocalPath.
ServerPath="$/proj/path/name.ext" - borked.
I've de-compiled DownloadFiles to see why: First it gets a list of server items, in our case just $/proj/path/name.ext. Then, it calculates the local path like this:
localItemPath = Path.Combine(LocalPath,VersionControlPath.MakeRelative(ServerItem, ServerPath));
In this line, the activity assumes that ServerPath is a path. If it's not, then MakeRelative will not recognize it, and the local path will be LocalPath/$/proj/path/name.ext, as the OP has observed.
Also, if ServerPath is not canonical - for example, $/proj/path/../path2, the same will happen. Solution: use VersionControlPath.GetFullPath(myNonCanonicalPath).
You need to grant the user running the build service with write permissions on the shared folder.
http://msdn.microsoft.com/en-us/library/cc668757.aspx
There are two separate Build activities, DownloadFiles for a folder ServerItem and a DownloadFile for a single file ServerItem.I'd expect it should work with DownloadFile.

Resources